1

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
});
2

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

3 Comments

The above code didn't work.. Now it is not accepting any file types, whatever the extension is. Here is the demo project in MVC where I am trying. github.com/maxpavlov/jQuery-File-Upload.MVC3/blob/master/…
So it went from working like a charm to not working at all? What changed? Also it doesn't look like you are trying to restrict at all now, is this a new issue altogether? Good luck.
Basically I tested your code in Regex tester it seem to work there. But when I added the same code in jQuery File Upload, it doesn't seem to like it, so thats where the problem is. Sorry I haven't tested completely when i said it worked. The link I gave is where I got that code, so i added "acceptFileTypes" attribute in my local machine. Your code is restricting all the file types.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.