Node.js 1gb csv file download - Error: request aborted

I have a problem with a large file upload. I tried to download smaller files and it works well, but when I try to download a larger file (700 mb or more), the node.js server gives 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)

He does not even reach the reading state.

I use

  • Google chrome
  • express 3.0

I turned on

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

And I think I should mention this; after receiving the above error, the file starts to load again and fails. Again, there is no problem with smaller files. So my question is, how can I efficiently transfer large files using this method, or is there a better way to do this? Thank.

+4
source share
2

:

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);

: felixge/node-formidable

+2

enctype="multipart/form-data"

+1

Source: https://habr.com/ru/post/1531716/


All Articles