Use the onSelect callback to inspect and filter files before they enter the upload queue.
Reject files based on custom criteria such as naming conventions or content checks.
Rules: Only files under 5 MB with .jpg, .png, or .pdf extensions are accepted.
Filenames containing spaces are rejected.
AjaxUploader.create('#uploader', {
uploadUrl: '/ajaxupload.axd/upload',
multiple: true,
onSelect: function(files) {
var allowed = ['.jpg', '.png', '.pdf'];
var maxSize = 5 * 1024 * 1024;
return files.filter(function(f) {
var ext = f.name.substring(f.name.lastIndexOf('.')).toLowerCase();
if (allowed.indexOf(ext) === -1) {
log('Rejected (type): ' + f.name);
return false;
}
if (f.size > maxSize) {
log('Rejected (size): ' + f.name);
return false;
}
if (f.name.indexOf(' ') !== -1) {
log('Rejected (spaces in name): ' + f.name);
return false;
}
log('Accepted: ' + f.name);
return true;
});
}
});