Priority-Based Upload Order
Assign priority to tasks so higher-priority files upload first.
(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; }
var uploader = new MultipleUpload('#demo', {
uploadUrl: '/api/upload',
multiple: true,
autoUpload: false,
sortBy: 'priority',
onFileAdded: function(task) {
var priority = task.fileName.startsWith('urgent') ? 10 : 0;
uploader.setTaskPriority(task.id, priority);
log(task.fileName + ' priority=' + priority);
},
onTaskStart: function(t) { log('Uploading: ' + t.fileName + ' (priority ' + t.priority + ')'); }
});
})();Deciding what goes first
setTaskPriority(task, priority) reorders the queue so the files that matter most transfer first. That is worth having whenever the queue is long enough that later items wait a noticeable time.
The case it is really for
The user drops twenty photos and immediately wants to see one of them, or a form needs one required document before it can submit while the rest are optional attachments. Both are the same shape: the queue's natural order is selection order, and selection order is rarely importance order.