Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Properly abort uploads
Add a new approach for flagging an upload as aborted because we can't
rely on the browser fully cancelling the request as we now seem to
receive an error response from the server instead of a jQuery "abort"
message.

Signed-off-by: Vincent Petry <[email protected]>
  • Loading branch information
PVince81 authored and backportbot[bot] committed Jan 13, 2022
commit 7ac4856b108db6ac76abb8b98c2d82952dec9c56
45 changes: 36 additions & 9 deletions apps/files/js/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,34 @@ OC.FileUpload.prototype = {
);
},

_delete: function() {
var self = this;
if (this.data.isChunked) {
this._deleteChunkFolder()
}
this.deleteUpload();
},

/**
* Abort the upload
*/
abort: function() {
if (this.data.isChunked) {
this._deleteChunkFolder();
var self = this;
if (this.aborted) {
return
}
this.data.abort();
this.deleteUpload();
this.aborted = true;
this._delete();
},

/**
* Fail the upload
*/
fail: function() {
this.deleteUpload();
if (this.data.isChunked) {
this._deleteChunkFolder();
if (this.aborted) {
return
}
this._delete();
},

/**
Expand Down Expand Up @@ -679,7 +687,13 @@ OC.Uploader.prototype = _.extend({
return;
}

delete this._uploads[upload.data.uploadId];
// defer as some calls/chunks might still be busy failing, so we need
// the upload info there still
var self = this;
var uploadId = upload.data.uploadId;
window.setTimeout(function() {
delete self._uploads[uploadId];
}, 5000)
},

showUploadCancelMessage: _.debounce(function() {
Expand Down Expand Up @@ -905,6 +919,7 @@ OC.Uploader.prototype = _.extend({
if ($uploadEl.exists()) {
this.progressBar.on('cancel', function() {
self.cancelUploads();
self.showUploadCancelMessage();
});

this.fileUploadParam = {
Expand Down Expand Up @@ -1075,14 +1090,18 @@ OC.Uploader.prototype = _.extend({
var upload = self.getUpload(data);
var status = null;
if (upload) {
if (upload.aborted) {
// uploads might fail with errors from the server when aborted
return
}
status = upload.getResponseStatus();
}
self.log('fail', e, upload);

self.removeUpload(upload);

if (data.textStatus === 'abort' || data.errorThrown === 'abort') {
self.showUploadCancelMessage();
return
} else if (status === 412) {
// file already exists
self.showConflict(upload);
Expand Down Expand Up @@ -1283,6 +1302,10 @@ OC.Uploader.prototype = _.extend({
fileupload.on('fileuploadchunksend', function(e, data) {
// modify the request to adjust it to our own chunking
var upload = self.getUpload(data);
if (!upload) {
// likely cancelled
return
}
var range = data.contentRange.split(' ')[1];
var chunkId = range.split('/')[0].split('-')[0];
data.url = OC.getRootPath() +
Expand Down Expand Up @@ -1317,6 +1340,10 @@ OC.Uploader.prototype = _.extend({

self.trigger('done', e, upload);
}).fail(function(status, response) {
if (upload.aborted) {
return
}

var message = response.message;
if (status === 507) {
// not enough space
Expand Down