如何使用javascript计算文件的md5哈希值 [英] How to calculate md5 hash of a file using javascript

查看:719
本文介绍了如何使用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

这篇关于如何使用javascript计算文件的md5哈希值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆