From 536bda7394e693c3bf2641ea9ea6c502a97cdc8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 15 Jan 2018 12:24:23 +0100 Subject: [PATCH] core: Initialise `progress.bytesTotal` as soon as upload starts This way our ETA calculations etc. will be correct even if it takes a very long time for the first progress event comes in. This helps especially with XHRUpload's `limit` option, where queued uploads will not be firing progress events at all until other uploads have finished. --- src/core/Core.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/Core.js b/src/core/Core.js index d437d9749..f8b182edf 100644 --- a/src/core/Core.js +++ b/src/core/Core.js @@ -583,7 +583,7 @@ class Uppy { const fileID = data.id // skip progress event for a file that’s been removed - if (!this.getState().files[fileID]) { + if (!this.getFile(fileID)) { this.log('Trying to set progress for a file that’s been removed: ', fileID) return } @@ -670,12 +670,14 @@ class Uppy { }) this.on('upload-started', (fileID, upload) => { + const file = this.getFile(fileID) this.setFileState(fileID, { - progress: Object.assign({}, this.getState().files[fileID].progress, { + progress: Object.assign({}, file.progress, { uploadStarted: Date.now(), uploadComplete: false, percentage: 0, - bytesUploaded: 0 + bytesUploaded: 0, + bytesTotal: file.size }) }) })