You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Start upload (the easiest way to reproduce is, to make the upload sequential and throttle network connection to 3G or slow)
First file is uploading and progress bar + loaded is increasing
After the first file is completed the progress & loaded is decreased
Reason
On loadend event the event.total and event.loaded are taken the Content-Length header from the response (see here).
In my case this bug occures because the uploaded file was 12000 bytes and the Content-Length was 300 bytes, because my i my response body there is a json like { successful: true }
I think, there is not correct to set the Content-Length as file.size, because this is only correct, when i return after the upload the uploaded image.
While debugging, i have found an older issue. In this issue there was tried so fix this problem, by adding a check for total = 0 bytes (#475),
This means, that the progress & loaded works only when i return with status 200 & no body.
Possible fix
The file.size should only be set in onloadstart event
In Event onprogress set always only file.loaded
In event onloadend (when file is uploaded) we should set file.loaded equal to file.size
An attempt to prove and model #1001 with a failing regression test
Unfortunately to do so I've also had to modify some internals...
Mirage upload handler 🌴
Adjusted this route handler to more accurately model a real upload request.
It now fires onloadstart, onprogress and onloadend rather then onprogress only.
The total value of the onloadend ProgressEvent is intentionally set to an arbitrary value.
⚠️ I don't think this is a breaking change, and I'd be surprised if it affected users of the mirage handler as it's a specific implementation detail of something this addon handles for users. No guarantees, though.
HTTPRequest 🌐
Setup so that onloadstart and onloadend may be called from the Mirage handler.
Shouldn't affect addon users.
Steps to reproduce
Reason
On
loadend
event theevent.total
andevent.loaded
are taken theContent-Length
header from the response (see here).In my case this bug occures because the uploaded file was 12000 bytes and the Content-Length was 300 bytes, because my i my response body there is a json like
{ successful: true }
I think, there is not correct to set the
Content-Length
asfile.size
, because this is only correct, when i return after the upload the uploaded image.While debugging, i have found an older issue. In this issue there was tried so fix this problem, by adding a check for total = 0 bytes (#475),
This means, that the progress & loaded works only when i return with status 200 & no body.
Possible fix
file.size
should only be set inonloadstart
eventonprogress
set always onlyfile.loaded
onloadend
(when file is uploaded) we should setfile.loaded
equal tofile.size
Actual code parts:
ember-file-upload/ember-file-upload/src/system/upload.ts
Lines 90 to 97 in d2ac4b2
ember-file-upload/ember-file-upload/src/system/http-request.ts
Lines 85 to 90 in d2ac4b2
The text was updated successfully, but these errors were encountered: