title: MD5 hash of a file using javascript
body: <p>I have to upload a file from the front end and calculate the md5 hash of the file.
  I tried to use crypto.js to generate the md5 but for images it is giving me wrong md5.
  I saw a website called onlinemd5.com and it is exactly what I need. </p>
  
  <p>Can anyone help me how to calculate the md5 hash of a file(text file, images, videos etc) using javascript?
  Is it possible to download the code from <a href="http://onlinemd5.com" rel="nofollow noreferrer">http://onlinemd5.com</a> and implement it? </p>
  
  <p>Note: I tried some of the suggestions in <a href="https://stackoverflow.com/questions/768268/how-to-calculate-md5-hash-of-a-file-using-javascript">How to calculate md5 hash of a file using javascript</a> but of no use.</p>
  
  <hr>
  
  <pre><code>$scope.upld = function(element){
      $scope.files = element.files;
      var file = $scope.files[0];
      var reader = new FileReader();
      reader.onload = function(){
          $scope.md5_val = CryptoJS.MD5(reader.result);
          $scope.upload_file();
          $scope.$apply();
      };
      reader.readAsBinaryString(file);
  };
  </code></pre>
  
  <p>The crypto.js is not calculating the image md5 correctly. I did not try the sparkmd5 js though. </p>