title: Jquery File Upload - How to limit number of files uploaded
body: <p>I am trying out Jquery File Upload from blueimp. The documentation says I should be able to limit the number of files to be uploaded with the maxNumberOfFiles setting. </p>
  
  <p>However, that doesn't seem to be working in my case. None of the others such as acceptFileTypes, loadImageMaxFileSize etc seem to be working either (probably I have to include other js files? - don't know really which ones or how to hook em up despite researching quite a lot) . I am using the basic version of the plugin. Here is how my code looks:</p>
  
  <p>JS files included:</p>
  
  <ol>
  <li>jquery_ui_widget.js</li>
  <li>jquery_iframe_transport.js</li>
  <li>jquery_file_upload.js</li>
  <li>tmpl.js</li>
  </ol>
  
  <p>The JS Code:</p>
  
  <pre><code>$('#fileupload').fileupload
    maxFileSize: 3 * 1024
    minFileSize: 1
    maxNumberOfFiles: maxFilesAllowed
    autoUpload: false
    loadImageMaxFileSize: 3 * 1024
    acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
    add: (e, data) =&gt;
      console.log 'add callback triggered'
  </code></pre>
  
  <p>The add callback is triggered for EVERY file. Even if I try to implement my own solution to limit the number of uploaded files, I would like to be able to know when all the calls to "add" are complete. In other words, if I have to implement the solution, it would look like </p>
  
  <ol>
  <li>Wait for add event on for each file. Maintain a counter to count each file on the add callback</li>
  <li>Know when all add event triggering is complete for <strong>ALL</strong> files -- HOW???</li>
  <li>See how many files were uploaded and prevent upload <strong>of all the files</strong> if they exceed the max number allowed and prompt for selecting a subset of files from initial selection to upload.</li>
  </ol>
  
  <p>The solution is purely client side for the images and the images directly upload to S3 but I need to prevent more than 3 uploads for each transaction. With the currently implementation I have, there is nothing that prevents the user from selecting his/her whole image folder and mess up the S3 bucket with ton of images. Amazon for its part will take as many files as are uploaded within the time the policy allows.</p>
  
  <p>The only way out of this imbroglio seems to be to route all uploads through the our servers which I am trying to desperately avoid due to scalability/performance issues. We are a very tiny startup with very minimal scaling capacity at this time. The other idea I have is to ask the server for a 30 second enabled policy for every file upload which seems rather cumbersome.</p>
  
  <p>Any other ideas/alternatives/suggestions/recommendations that people have tried/used that worked?</p>