Search code examples
jqueryjquery-pluginsjquery-file-uploadblueimp

Restrict file types in BlueImp JQuery File Upload


Is there anyway we can restrict the file types in JQuery File Upload. From the documentation we have below code, but that is only for allowed file types. I want something for restricting file types.I want to allow all the file types but restrict .exe and .js files. Please let me know if there is any workaround for this.

$('#file_upload').fileUploadUIX({
    maxFileSize: 5000000, // Maximum File Size in Bytes - 5 MB
    minFileSize: 100000, // Minimum File Size in Bytes - 100 KB
    acceptFileTypes: /(zip)|(rar)$/i  // Allowed File Types
});

Solution

  • You may need to alter the code a little more but I was able to get what you wanted by altering the regex to the following:

     $('#file_upload').fileUploadUIX({
            maxFileSize: 5000000, // Maximum File Size in Bytes - 5 MB
            minFileSize: 100000, // Minimum File Size in Bytes - 100 KB
            acceptFileTypes: /(\.|\/)(?!exe|js)$/i  // Allowed File Types
        });
    

    enter image description here