Multer: Upload progress

Created on 9 Oct 2015  路  7Comments  路  Source: expressjs/multer

How do I track upload progress in multer?

Most helpful comment

This one seems good if you don't want to roll your own: https://www.npmjs.com/package/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, _)

All 7 comments

Track how much of the stream is consumed and compare it to the stated Content-Length.

and where do I track the stream consumption? multer doesnt have many callback functionalities...

for instance:
app.post('/posts', upload.single('post_file'), function(req, res){
//callback for completed file, but where do I get partial results?
});

This one seems good if you don't want to roll your own: https://www.npmjs.com/package/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, _)

@ Can you give a sample complete working example?
I'm using var upload = multer({storage: storageConfig}) and inject upload.single('alcon') to my route

You can try to listen to the event upload.onprogress
This works fine for me. http://stackoverflow.com/a/36725089/6029652

This one seems good if you don't want to roll your own: https://www.npmjs.com/package/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, _)

@LinusU
Can you expound this approach?
It seems to be what I need but the progress event only fires once at 100%.

It seems to be what I need but the progress event only fires once at 100%.

I haven't tried that package myself, maybe it's a bug in progress-stream?


Since this isn't specific to Multer, I think it's better to open a post at Stack Overflow were you should be able to get help with this :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChristianRich picture ChristianRich  路  4Comments

NobleUplift picture NobleUplift  路  4Comments

Gabxi picture Gabxi  路  3Comments

Paul-Morris picture Paul-Morris  路  3Comments

tjabdoullah picture tjabdoullah  路  4Comments