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.
This commit is contained in:
Renée Kooi 2018-01-15 12:24:23 +01:00
parent be6fa4a105
commit 536bda7394
No known key found for this signature in database
GPG key ID: 30516CF2A8E63718

View file

@ -583,7 +583,7 @@ class Uppy {
const fileID = data.id
// skip progress event for a file thats been removed
if (!this.getState().files[fileID]) {
if (!this.getFile(fileID)) {
this.log('Trying to set progress for a file thats 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
})
})
})