2

I am using jQuery-File-Upload with rails 3, it works very well. But I didn't find anything about how to validate the extension or the content type of the upload file on the client-side.

Is there a way to do that?

Of cause I will anyway validate it by Paperclip at server-sid, but I think it would be better to validate it once at client-side.

2 Answers 2

2

acceptFileTypes

The regular expression for allowed file types, matches against either file type or file name as only browsers with support for the File API report the file type.

Type: Regular Expression
Example: /(\.|\/)(gif|jpe?g|png)$/i

See https://github.com/blueimp/jQuery-File-Upload/wiki/Options

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

Comments

0

The question implicates that you (opposite to the majority) realize that when you detect on just the extention, that you're not checking mime type.

In HTML5 you can use the accept attribute:

<input type="file" accept="video/*" />

You could use multiple (commaseperated?) values. But the specification says space-seperated, but in reality I only see comma-seperated values. Mind: in HTML5 capable browsers adding more validation is redundant.

But in case your question related to other use (like drag/drop file uploads), then you could use javascript in stead of jquery:

if(!(file.type.indexOf('video/') == 0)) {
  alert('nope');
  return false;
  }

Needless to say is that you also should validate on the server side.

Comments

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.