Friday, 5 May 2017

how to upload a file from android using node js?

i have a code to upload a file via web.

var http = require('http');
var formidable = require('formidable');
var fs = require('fs');

http.createServer(function (req, res) {
 if (req.url == '/fileupload') {
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
  var oldpath = files.filetoupload.path;
  var newpath = '' + files.filetoupload.name;
  if(newpath == '')
  {
    res.write('sorry...')
    res.end()
  }
  else{
  fs.rename(oldpath, newpath, function (err) {
    if (err) throw err;
    res.write('File uploaded and moved!');
    res.end();
  });}
 });
  } else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<form action="fileupload" method="post" enctype="multipart/form-data">');
res.write('<input type="file" name="filetoupload"><br>');
res.write('<input type="submit">');
res.write('</form>');
return res.end();

} }).listen(8080); i want to know how to upload a file from android using multipart. and upload it in my local directory.



via RajaSekar

No comments:

Post a Comment