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?
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:
Content-Length and sets up a spy on the data and end events.data event, calculate the progress by summing earlier events and this event's payload length
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
progressevent to get info about how much stuff is uploaded.Using it together with the
<progress> elementis super easy.