4

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.

2
  • 3
    you need to use formidable, just google node formidable. don't use bodyParser, it has been deprecated. Commented Mar 14, 2014 at 8:31
  • Since CSV can often be compressed quite will you might find it advantageous to have the browser zip the CSV file before sending it gildas-lormeau.github.io/zip.js some people have also used Flash to create file uploaders that compress files stackoverflow.com/questions/8377268/… Commented Jul 7, 2014 at 4:10

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.