Cancelling a pending upload starts new upload even if another is in progress
Hi. I'm using 2.3.4. These are the steps to reproduce:
- Launch 3 uploads
- While first is still uploading cancel the last one.
- This will cause the second upload to be started even when the first is not finished yet. Now there are two running in parallel.
For me this behavior seems strange. I tracked down the issue to the _onCompleteItem() funtion which is called by cancelItem(). It triggers the upload of the next item without checking if there is an upload ongoing.
In fact, it sets isUploading to false in all cases:
FileUploader.prototype._onCompleteItem = function _onCompleteItem(item, response, status, headers) {
item._onComplete(response, status, headers);
this.onCompleteItem(item, response, status, headers);
var nextItem = this.getReadyItems()[0];
this.isUploading = false;
if (isDefined(nextItem)) {
nextItem.upload();
return;
}
this.onCompleteAll();
this.progress = this._getTotalProgress();
this._render();
};
My solution is to remove isUploading = false and add an isUploading check which prevents nextItem.upload() if true. Does that make sense?
Hmmm. My solution does not always trigger a new upload when one is finished and something has been cancelled in between. More work...
I can not reproduce your behavior. When I start 3 uploadings then a "cancel" button is enabled only for current uploading
Hi nervgh. How did you test? I have my own upload manager built with angular which uses your module to mange the uploads. I give the user buttons to cancel the ongoing and pending uploads. So I do not disable buttons. Using that setup I can see the bug.
I'm also getting this problem on v2.5.0. I've setup to upload multiple files and to start upload after adding the file. So, the first file started uploading. Then, on the front-end, I can see a list of files I've previous selected via the File Browser. The first one shows it's uploading while the others are on the queue. The other ones can be removed from the list. When a file is removed, I would call fileItem.cancel(). This would kick the second file on the list to make another upload request while the first one is still being uploading. I don't think this is the correct behavior.
When I rolled back to v2.1.3, I didn't see this problem.
self.fileUploaderConfig = {
url: SOME_URL,
removeAfterUpload: true,
...
onAfterAddingFile: function (item) {
item.upload();
},
...
};
At Cancel-All - set isReady = false item.isReady = false