Fluctuating `resumableTotalChunks` parameter
dannydjrs opened this issue · 0 comments
dannydjrs commented
During a large upload, the sent resumableTotalChunks
parameter can sometimes not be the actual value and can differ between chunks sent.
Dev Notes
I have looked into the possible reason and have narrowed it down to the following:
ResumableFile.bootstrap
is called to initialise all theResumableChunks
and store them in theResumableFile.chunks
array.- Once
bootstrap
is completed the upload of theResumableFile
is allowed to begin - However, on completion, the
bootstrap
function has not added any chunks to thechunks
array - This is due to the
window.setTimeout
surrounding the actual push of the new chunk (making it run asynchronously), forcing thebootstrap
function to complete before all thesetTimeout
contents have completed.
- Therefore, this is allowing
upload
to be started whilst theResumableChunks
are still being added to thechunks
array - As the
resumableTotalChunks
parameter is determined from the length of thechunks
array, this is what it causing the fluctuation.
Example
Example request parameters sent:
- note the change in
resumableTotalChunks
- also how it is not the actual value of 984
resumableChunkNumber=2&resumableChunkSize=1048576&resumableCurrentChunkSize=1048576&resumableTotalSize=1031744025&resumableType=&resumableIdentifier=###&resumableFilename=###&resumableRelativePath=###&resumableTotalChunks=394
resumableChunkNumber=3&resumableChunkSize=1048576&resumableCurrentChunkSize=1048576&resumableTotalSize=1031744025&resumableType=&resumableIdentifier=###&resumableFilename=###&resumableRelativePath=###&resumableTotalChunks=400
Possible fixes
- Remove the
setTimeout
around the push to the array - Determine the totalChunks using the
fileSize
andchunkSize
rather than length ofchunks
array