diff --git a/ember-file-upload/src/system/upload.ts b/ember-file-upload/src/system/upload.ts index 016f947e..64d6dfb3 100644 --- a/ember-file-upload/src/system/upload.ts +++ b/ember-file-upload/src/system/upload.ts @@ -92,13 +92,20 @@ export function upload( if (!evt.lengthComputable || evt.total === 0) return; file.loaded = evt.loaded; - file.size = evt.total; + // It occurs that the evt.total is not always correct. + // For this reason we should hold the max file size. + // The correct should be returned while progress + file.size = Math.max(file.size, evt.total); file.progress = (file.loaded / file.size) * 100; }; request.onprogress = function (evt) { if (!evt) return; - if (!evt.lengthComputable || evt.total === 0) return; + // We need to check also for isUploadComplete, because the browsers brings sometimes the onprogress after onloadend event + if (!evt.lengthComputable || evt.total === 0 || file.isUploadComplete) + return; + + file.size = evt.total; // When the progress is completed there is possible that we get the `Content-Length` response header of the upload endpoint as loaded / total. // There is possible that `Content-Length` is lower or higher than the already loaded bytes. @@ -118,6 +125,7 @@ export function upload( file.loaded = file.size; file.progress = (file.loaded / file.size) * 100; + file.isUploadComplete = true; }; request.ontimeout = () => { diff --git a/ember-file-upload/src/upload-file.ts b/ember-file-upload/src/upload-file.ts index f1d65d24..6cfd1ed5 100644 --- a/ember-file-upload/src/upload-file.ts +++ b/ember-file-upload/src/upload-file.ts @@ -87,6 +87,11 @@ export class UploadFile { * range of 0 to 100. */ @tracked progress = 0; + + /** + * When upload has finished this property will be set to true + */ + @tracked isUploadComplete = false; /** * The current state that the file is in.