onBeforeUpload Gate
Return false from onBeforeUpload to skip uploading a specific 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,
onBeforeUpload: function(task) {
if (task.fileSize > 2 * 1024 * 1024) {
log('BLOCKED: ' + task.fileName + ' is over 2MB, skipping upload');
return false;
}
log('Uploading: ' + task.fileName);
}
});
})();A hook that can veto
onBeforeUpload runs after a file has passed validation and before its transfer starts, which makes it the place for checks the component cannot make: asking your server whether the user still has quota, confirming an overwrite, attaching metadata the user just typed.
Returning false stops the file
The veto cancels that task rather than leaving it stranded in the queue. If you use it, tell the user why — a file that quietly refuses to upload with no explanation is the hardest kind of problem to report, because there is nothing to describe.