title: Checking file size/type before upload using Paperclip and Rails
body: <p>I have a Rails app which allows users to upload videos (on a local, rather than a cloud, server).</p>
  
  <p>I'm using Paperclip 3.1.4 and Paperclip-ffmpeg 0.9.0.</p>
  
  <p>Everything is working fine and dandy, but the problem is that, if a user uploads a file in the wrong format, or greater than the size allowed by the validation rules, the error message is not displayed until after the upload has taken place - not great for usability, particularly if it takes 10 minutes to upload a file in the wrong format!</p>
  
  <p>So, is there any way I can integrate, let's say, jQuery (which I'll admit to knowing very little about) into my model, so that the file can be checked as soon as the user hits the "Upload" button, rather waiting until the app has tried to upload the file (if that makes sense)?</p>
  
  <p>Here's some code from my model (I've stripped the unimportant stuff):</p>
  
  <pre><code>class Video
  
       attr_accessible :sourcefile
  
       has_attached_file :sourcefile
  
       ...
  
       validates_attachment_size :sourcefile, :less_than =&gt; 250.megabytes, 
          :message =&gt; "Sorry, your video is too large"
       validates_attachment_content_type :sourcefile, :content_type =&gt; [...],
          :message =&gt; "Sorry, the file format is wrong"
  
  end
  </code></pre>
  
  <p>So, is there any way I could "bolt on" a function to trigger some form of JavaScript to check the file before it is uploaded and these validation rules kick in place (which I'd like to keep on the off chance that the user has JavaScript disabled in their browser)?</p>
  
  <p>It would also be good if there was another function I could use to trigger a jQuery-esque progress bar if the file type is correct, but that's not necessarily required at this stage.</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT -</strong> Thanks to Kevin B below who noted that jQuery/JavaScript cannot be used to check file sizes. Oh well! Is there any other approach I could take? The server is running nginx, but I'd rather not go there - I'd prefer to deal with the issue within the Rails code itself.</p>