Multer: Upload progress

Created on 25 Jan 2016  路  4Comments  路  Source: expressjs/multer

I'm using multer to upload files via Ajax and it works very well. However, I can't seem to tap into the upload progress so I can feed that back to the client and display a progress bar. Is this possible?

Most helpful comment

It's actually possible on both sides, although I would recommend doing it on the client side to avoid the feeding back step.

Use the progress event to get info about how much stuff is uploaded.

Using it together with the <progress> element is super easy.

var req = new XMLHttpRequest()
var progress = document.createElement('progress')

// ...

req.upload.addEventListener('progress', function (ev) {
  if (!ev.lengthComputable) return

  progress.max = ev.total
  progress.value = ev.loaded
})

All 4 comments

It's actually possible on both sides, although I would recommend doing it on the client side to avoid the feeding back step.

Use the progress event to get info about how much stuff is uploaded.

Using it together with the <progress> element is super easy.

var req = new XMLHttpRequest()
var progress = document.createElement('progress')

// ...

req.upload.addEventListener('progress', function (ev) {
  if (!ev.lengthComputable) return

  progress.max = ev.total
  progress.value = ev.loaded
})

Please reopen if you need more assistance

you have a server side example?

@iscorporacion you can look at the incoming request and hook up data notifications before passing the stream to Multer. This is not specific to Multer so I would recommend making a StackOverflow post if you need more assistance, but basically, it would work something like this:

  • Add a middleware to express that reads the Content-Length and sets up a spy on the data and end events.
  • On every data event, calculate the progress by summing earlier events and this event's payload length
Was this page helpful?
0 / 5 - 0 ratings

Related issues

josephstgh picture josephstgh  路  3Comments

Paul-Morris picture Paul-Morris  路  3Comments

Gabxi picture Gabxi  路  3Comments

edi picture edi  路  4Comments

bpetty-formfast picture bpetty-formfast  路  3Comments