Pausing the whole upload queue does not work as expected
Opened this issue · 0 comments
Hello everyone, I'm not a native english speaker, so excuse me for my English.
First of all, We're using flowjs in a production environment and we are quite satisfied. so, Thank you!
I just found an issue in pause/resume feature. when you call pause method on the main upload queue (not on an individual file), the queue does not stop immediately. It cancels the current request (if any) and sends other files in the queue.
Let me give you an example: Imagine you have 3 files in the queue and file 1# is being uploaded. When you call pause on the flow object, you expect the whole upload thing to stop, right? Ok, requests belonging to file 1# are canceled. But, what actually happens is that files 2# & 3# also starts to upload.
I just digged into the code, and found this:
pause: function () {
each(this.files, function (file) {
file.pause();
});
}
So, when calling the pause method, we actually pause each individual file. Now, check these two methods which belong to FlowFile
:
pause: function () {
this.paused = true;
this.abort();
}
abort: function (reset) {
this.currentSpeed = 0;
this.averageSpeed = 0;
var chunks = this.chunks;
if (reset) {
this.chunks = [];
}
each(chunks, function (c) {
if (c.status() === 'uploading') {
c.abort();
this.flowObj.uploadNextChunk();
}
}, this);
}
I think the process for pausing the whole queue, is a little different from pausing each file. As you can see, when we pause a file, we abort any xhr requests associated to it and we go forward in the upload queue, by calling the uploadNextChunk
method. So, back to our example, when file 1# is paused, we go forward and chunks from file 2# will start to upload. We should set paused state in all files in one go, and not sequentially. This way, uploadNextChunk
will see the paused state of files, and no additional requests will be performed. #7