How to calculate md5 hash of a file using javascript

LuRsT picture LuRsT · Apr 20, 2009 · Viewed 133.2k times · Source

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

Answer

Paul Dixon picture Paul Dixon · Apr 20, 2009

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: