javascriptmd5

How to calculate md5 hash of a file using javascript


Is there a way to calculate the MD5 hash of a file before the upload to the server using Javascript?


Solution

  • While there are JS implementations of the MD5 algorithm, older browsers are generally unable to read files from the local filesystem.

    I wrote that in 2009. So what about new browsers?

    With a browser that supports the FileAPI, you can read the contents of a file - the user has to have selected it, either with an <input> element or drag-and-drop. As of Jan 2013, here's how the major browsers stack up:

    How?

    See the answer below by Benny Neugebauer which uses the MD5 function of CryptoJS