Duplicate Files
Prevent duplicate file names from being added to the queue using the onSelect callback to track added file names.
Drag & drop files here (no duplicates)
<div id="myUploader" class="mu-uploader">...</div>
var addedNames = {};
var uploader = new MultipleUpload(document.getElementById('myUploader'), {
uploadUrl: '/api/upload',
onSelect: function(file) {
if (addedNames[file.name]) {
showError(file.name + ' has already been added.');
return false;
}
addedNames[file.name] = true;
return true;
},
onQueueRemove: function(file) {
delete addedNames[file.name];
}
});
Catching the same file twice
preventDuplicates compares name and size against both the current queue and files already completed in this session. It catches the ordinary accident — selecting a folder, then selecting it again because the first attempt did not look like it worked.
What that comparison misses
The same image saved under two names is not a duplicate by this test, and two unrelated files that happen to share a name and size are. For real content identity you need a hash: computeHash with SHA-256, and dedupe on the server against its own copies.