title: Laravel, FineUploader and FileReader API: compare hash of file before uploading
body: <p>I'd like to compare the hashed version of the file against the data stored in the database, so I can abort duplicate uploads.</p>
  
  <p>Being quite "new" to the subjects of hashing and the FileReader API, I'm finding the process a bit confusing.
  I am using the frontend library SparkMD5.js</p>
  
  <p>Test n1 compare two strings:</p>
  
  <pre><code>// frontend
  $.post(url, {sparkMD5('random text')})
  
  // backend
  $input-&gt;hash == md5('random text')  // outputs true
  </code></pre>
  
  <p>Test n2 - inside fineuploader <code>onSubmit</code> event handler</p>
  
  <pre><code>// frontend
  var file = this.getFile(id);
  var reader = new FileReader();
  //
  reader.onload = function(e) {
    var data = reader.result;
    var hexHash = SparkMD5.hash(data);
    console.log(hexHash);
  }
  
  var res = reader.readAsDataURL(file); // or reader.readAsBinaryString(file)
  
  ......
  
  //backend
  $file = Input::file('qqfile');
  $hash = md5(file ) // or md5_file(file )
  $hash == $input-&gt;hexHash // outputs false
  </code></pre>
  
  <p>My questions:</p>
  
  <p>1) Why is the result of <code>md5($file) == md5_file($file) \\ false</code> ?</p>
  
  <p>2) What's the correct way of reading a file <code>readAsDataURL or readAsBinaryString</code> ?</p>
  
  <p>3) Is there a way to read and hash the result of fineuploader's <code>getFile(id)</code> which returns <code>File or Blob</code>, without using filereader api?</p>
  
  <p>Answers to the above questions may be considered broad and out of scope of my immediate problem, but i'd like to understand the subject as best as possible.</p>
  
  <p>Thanks.</p>