Restricting Uploads by File Type

Archived from the Transloadit support forum. Originally posted on April 29, 2011; details may be outdated, see our docs for current behavior. Original thread

Hi, is there a way to restrict uploads by file type? In my case I would like to just store original uploads, without any encoding, and would like to notify the users that image file types are not being processed.

Hey there,

you can use our jQuery plugin and inspect the extensions of the files prior to their upload with the onChange event of your file input field.

Check out this function, it may be useful for you:

function fileTypeFromExt(val, def) {

var
    ext = val.split('.').pop().toLowerCase(),
    type = def,
    imageExtensions = ['jpg', 'jpeg', 'tiff', 'png', 'gif', 'bmp'];

for (var i = 0; i < imageExtensions.length; i++) {
    if (imageExtensions[i] == ext) {
        type = 'image';
        break;
    }
}
return type;

}

Let me know if that helps.

Kind regards,
Tim

Closing this for now - please feel free to reopen this ticket if you feel the need to.

Kind regards,
Tim