Reputation: 33
I have a file uploader that handles very large files. Lots of times the users will cancel an upload. There does not appear to be any way to make the browser cancel the XHR POST that is handling it. Consequently, progress and complete events fire much later and the upload actually completes. Presumably there must be an XHR object embedded in the uploader somewhere that I could call abort on, but I see nothing in the API docs, or in a console dump of the uploader object.
Upvotes: 2
Views: 227
Reputation: 3568
If your goal is to support only the HTML5 uploader (and not the Iframe or the Flash version), then you can do something like that:
define(['dojo/_base/declare', 'dojox/form/Uploader'], function(declare, Uploader) {
return declare([Uploader], {
xhrRequest: null,
createXhr: function() {
this.xhrRequest = this.inherited(arguments);
return this.xhrRequest;
},
cancel: function() {
if (this.xhrRequest && this.xhrRequest.abort) {
this.xhrRequest.abort();
}
}
});
});
dojox.form.Uploader
cancel
method when you want to cancel the upload.But remember: this will work only with the HTML5 uploader.
Upvotes: 1