Tracking progress of file upload in multer nodejs

Furious picture Furious · Feb 9, 2016 · Viewed 8.7k times · Source

How to track progress of a file getting uploaded to NodeJs server .I am using multer in server side to upload files. ?

Do i need to send some kind of information to the client , So that client gets the upload progress OR this is done internally & client can track progress on its on.

Below is the code i am using to upload file :

var multer = require('multer');
app.use(multer({dest:'./tmp',limits: {fileSize: 4*1024*1024}}).single('upload'));


router.post('/upload',function(req,res){
 console.log(req.file);
});

Answer

arieljannai picture arieljannai · Jun 21, 2016

Here's an answer by LinusU at the project github's page (he suggests using progress-stream):

Pipe req to that one and give it to multer.

    var p = progress()
    var upload = multer().single('file')

    req.pipe(p)
    p.headers = req.headers

    p.on('progress', _)
    upload(p, res, _)