Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload progress incorrect in Google Chrome #1016

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ember-file-upload/src/system/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -118,6 +125,7 @@ export function upload(

file.loaded = file.size;
file.progress = (file.loaded / file.size) * 100;
file.isUploadComplete = true;
};

request.ontimeout = () => {
Expand Down
5 changes: 5 additions & 0 deletions ember-file-upload/src/upload-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export class UploadFile {
*/
@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.
*/
Expand Down