File Upload: Validating Extensions
I was searching for a way to validate a file against an allowed set of extensions before uploading. My application uses file_column plugin to store video files and I am using mongrel_upload_progress to track the upload. The maximum file size allowed is 50Mb so there was a need to have validation at both client as well as server side.
Model Validation
Client Side javascript validation
mongrel_upload_progress plugin uses following code to submit the form in a hidden iframe. Modify submitUploadForm method as shown:
The advantages of this approach are:
File is validated at both sides to avoid unnecessary uploading of file before model validation. Good for big files.
In case JS is disabled, the file is still validated.


