Question

I have a problem with large file upload. I have tried to upload smaller files and it's working nicely but when I try to upload larger file (700mb and more) the node.js server is giving me an error:

Error: Request aborted at IncomingMessage.onReqAborted (/home/xxx/node_modules/express/node_modules/connect/node_modules/multiparty/index.js:131:17)
    at IncomingMessage.EventEmitter.emit (events.js:92:17)
    at abortIncoming (http.js:1911:11)
    at Socket.serverSocketCloseListener (http.js:1923:5)
    at Socket.EventEmitter.emit (events.js:117:20)
    at TCP.close (net.js:465:12)

Its not even reaching to reading state.

I use

  • Google chrome
  • express 3.0

I have included

app.use(express.bodyParser({limit: '2048mb'}));

Also I think I should mention this; after getting the above error, file starts to upload again and fails. Again, there is no issue with smaller files. So my question is how am I able to stream large files effectively with this method, or is there a better method for doing this? Thanks.

Was it helpful?

Solution

What about the following code:

var formidable = require('formidable'),
    http = require('http'),
    util = require('util');

http.createServer(function(req, res) {
  if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
    // parse a file upload
    var form = new formidable.IncomingForm();

    form.parse(req, function(err, fields, files) {
      res.writeHead(200, {'content-type': 'text/plain'});
      res.write('Received upload:\n\n');
      res.end(util.inspect(files));
    });

    return;
  }

  // show a file upload form
  res.writeHead(200, {'content-type': 'text/html'});
  res.end(
    '<form action="/upload" enctype="multipart/form-data" method="post">'+
    '<input type="file" name="upload" multiple="multiple"><br>'+
    '<input type="submit" value="Upload">'+
    '</form>'
  );
}).listen(80);

Source : felixge/node-formidable

OTHER TIPS

At the client side, you need to mention enctype="multipart/form-data"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top