onCancel Callback
Detect when a user cancels an upload task.
(function() {
var logEl = document.getElementById('log');
function log(m) { var d = document.createElement('div'); d.className='pkg-log-entry'; d.textContent=m; logEl.appendChild(d); logEl.scrollTop=logEl.scrollHeight; }
new MultipleUpload('#demo', {
uploadUrl: '/api/upload',
multiple: true,
onCancel: function(file, task) {
log('Cancelled: ' + (file ? file.name : task.fileName));
},
onTaskStart: function(t) { log('Started: ' + t.fileName); }
});
})();Knowing when the user backs out
onCancel fires when an upload is cancelled, which is your cue to undo whatever you set up when it started: re-enable a submit button, clear a placeholder row, release a reserved slot. Pairing it with onTaskStart keeps that bookkeeping symmetrical.
Cancelling the request is not cleaning up
Aborting the transfer stops the browser sending; it does not remove whatever the server already wrote. With plain uploads that can leave a partial file, so either write to a staging location that a later step promotes, or have the cancel path call your delete endpoint. Chunked uploads sidestep it: an incomplete chunk set was never assembled.