Filter on Select
Intercept file selection and apply custom filters before files are added to the queue.
What you should see: a rule the built-in validators do not cover, applied in
onSelect: files are inspected and can be dropped before they ever reach the queue.var uploader = CoreUpload.create('#filter-uploader', {
uploadUrl: '/api/upload/upload',
multiple: true,
autoUpload: true,
// onSelect receives the WHOLE selection; the array you return replaces it.
onSelect: function(files) {
return files.filter(function (file) {
// Reject files larger than 5MB
if (file.size > 5 * 1024 * 1024) {
alert(file.name + ' is too large (max 5MB)');
return false; // prevent file from being added
}
// Reject non-image files
if (!/\.(jpg|jpeg|png|gif)$/i.test(file.name)) {
alert(file.name + ' is not an image');
return false;
}
return true; // accept the file
});
}
});