adopted-ember-addons / ember-file-upload

File uploads for Ember apps
https://ember-file-upload.pages.dev/
Other
201 stars 119 forks source link

`loaded` & `progress` are not correct when file is upload #1001

Closed mkszepp closed 10 months ago

mkszepp commented 11 months ago

Steps to reproduce

  1. Add two or more files into queue
  2. Start upload (the easiest way to reproduce is, to make the upload sequential and throttle network connection to 3G or slow)
  3. First file is uploading and progress bar + loaded is increasing
  4. 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 (https://github.com/adopted-ember-addons/ember-file-upload/pull/475), This means, that the progress & loaded works only when i return with status 200 & no body.

Possible fix

Actual code parts: https://github.com/adopted-ember-addons/ember-file-upload/blob/d2ac4b21b99d764a715fbde8625750d7cadf8c68/ember-file-upload/src/system/upload.ts#L90-L97

https://github.com/adopted-ember-addons/ember-file-upload/blob/d2ac4b21b99d764a715fbde8625750d7cadf8c68/ember-file-upload/src/system/http-request.ts#L85-L90

gilest commented 10 months ago

Hey @mkszepp thanks for the detailed rundown. What you've described makes sense and I've suspicious that these progress numbers are not correct myself