如何使用javascript计算文件的md5哈希值

问题描述:

有没有办法在使用Javascript上传到服务器之前计算文件的MD5哈希?

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

MD5算法有 JS实施旧浏览器一般无法读取文件来自本地文件系统

我在2009年写过。那么新浏览器呢?

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

使用支持 FileAPI 的浏览器,您*可以*阅读内容文件 - 用户必须选择它,使用< input> 元素或拖放。截至2013年1月,主流浏览器如何叠加:

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:

  • FF 3.6 supports FileReader, FF4 supports even more file based functionality
  • Chrome has supported the FileAPI since version 7.0.517.41
  • Internet Explorer 10 has partial FileAPI support
  • Opera 11.10 has partial support for FileAPI
  • Safari - I couldn't find a good official source for this, but this site suggests partial support from 5.1, full support for 6.0. Another article reports some inconsistencies with the older Safari versions