4

I see quite a few articles on how to handle chunked file uploading via Node and Express; for example:

This seems like a lot of work. Surely there are Node packages available which make it simple to handle chunked uploads? I've looked on NPM but haven't found anything of the sort. I'd like to just upload to my own server and not to a remote file store like S3.

Chad Johnson
  • 21,215
  • 34
  • 109
  • 207

1 Answers1

-2

i think you can handle chunk upload in express without needing any module

app.post('/anyUrl', function(req, res){
    var size = 0;

    req.on('data', function (data) {
        size += data.length;
        console.log('Got chunk: ' + data.length + ' total: ' + size);
    });

    req.on('end', function () {
        console.log("total size = " + size);
        res.send("response");
    }); 

    req.on('error', function(e) {
        console.log("ERROR ERROR: " + e.message);
    });


});

you can try the obove code making post requests

var fs = require('fs'); var request = require('request'); fs.createReadStream('path/to/file').pipe(request.post('http://localhost:3000/anyUrl'));

Dinesh Agrawal
  • 326
  • 1
  • 3
  • While this does provide access to the data with each chunked upload, it does not provide a way to deal with boundaries. – Chad Johnson May 10 '16 at 00:57
  • Downvoted because of Chad's comment, this does not address the actual chunking protocol in HTTP you should be looking at HTTP Headers letting you know which bytes are being sent, not assume they arrive in order. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests – Ruan Mendes Dec 30 '17 at 15:10