title: How to detect corrupt very large image files with javascript and jquery-file-upload?
body: <p>I am using jquery-file-upload in a rails app and I need to prevent corrupted images from being uploaded because users are trying to upload corrupt image files with valid file extensions.</p>
  
  <p>Would like to verify client side using javascrpt to avoid the long delay for verification on server with large files over 50 MB. </p>
  
  <p>I can check the file type but how would I reliably verify a very large valid and uncorrupted jpg or tif image using jquery/native javascript/jquery-file-upload?</p>
  
  <pre><code>$('form[id*=photo]').fileupload({
    dataType: 'script',
    pasteZone: null,
    sequentialUploads: true,
    formData: {fileupload: 'ajax'},
    add: function(e, data) {
      if($('#photo_id').val() == ""){
          data.type = 'POST';
      }else{
          data.type = 'PUT';
          data.url = "/photos/" + $('#photo_id').val();
      }
      if(this.id != "new_photo"){
          data.type = 'PUT';
      }
      types = /(\.|\/)(jpe?g|tif|tiff)$/i;
      file = data.files[0];
       if( types.test(file.type) || types.test(file.name) ) {
          data.context = $(tmpl("template-upload", file));
          $('.upload').remove();           
          $('#progbar').append(data.context);
          $('#control-group-progress').show();
          data.submit();
       } else {
           alert("We're sorry but the file " + file.name + " is not in a supported tiff or jpg image file format.  Please select a jpeg (jpg) or tiff file.  Thanks!");
       }
    },
    progress: function(e, data) {
     if(data.context) {
        progress = parseInt(data.loaded / data.total * 100, 10);
        progress = parseInt(progress * 0.9, 10);
        data.context.find('.bar').css('width', progress + '%');    
        data.context.find('.progress_percent').html(progress + "%");    
      }
    },
    always: function(e, data) {
      data.context.find('.bar').css('width', '100%');    
      data.context.find('.progress_percent').html("100%");
    }
  }); 
  </code></pre>