如何使用 Javascript 或 Flash 获取用户文件的哈希值?
我需要做的是在网页上提供一个文件浏览器框,用户可以在其中从计算机中选择一个文件,并通过 javascript(或必要时使用 flash)返回某种哈希值,例如 CRC、MD5 或 SHA1。 我不想将整个文件上传到网络服务器,因为我希望在此使用一些相当大的文件。
基本上,我正在制作一个脚本,将这些值与各种 META 数据相关联,从而无需完全上传即可识别文件。
知道我该怎么做吗? 对我来说,在服务器端执行此操作很容易,但是,正如我所说,将会检查一些相当大的文件,我不想占用太多服务器的带宽。
What I need to do is provide a file browser box on a web page where a user selects a file from their computer and, through javascript (or flash if necessary), some sort of Hash is returned such as CRC, MD5 or SHA1. I would prefer not to have to upload the entire file to the web server, as I expect some rather large files to be used in this.
Basically I am making a script that associates these values with META data of sorts, allowing the files to be identified without having to be uploaded completely.
Any idea how I would go about doing this? It'd be easy for me to do it on the server side, but, as I said, there will be some rather large files checked and I don't want to eat up too much of the server's bandwidth.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 Flash 来完成此操作,前提是用户拥有 Flash Player 10。
这是一个教程
另外: 在 FP10 中读写本地文件
You can do it with Flash, provided that the user has Flash Player 10.
Here is a tutorial
Also: Reading and writing local files in FP10
这对于 JavaScript 来说传统上是不可能的,但如果则可能是这样W3 文件上传规范曾经流行起来。
Firefox 3 中提供了一个变体:
对于其他浏览器,您必须回退到 Flash 和/或服务器端哈希。
这是 SHA-1 的额外 JS 实现:
This is traditionally not possible with JavaScript, but it may be if the W3 File Upload spec ever catches on.
A variant is available in Firefox 3:
For other browsers you would have to fall back to Flash and/or server-side hashing.
Here's a bonus JS implementation of SHA-1 for you:
这对于 Javascript 来说是不可能的,因为无法访问文件系统。 我知道这可以通过 Silverlight 来完成。 也许有Flash经验的人可以回答。
This is not possible with Javascript because of there is no access to the file system. I know this can be done with Silverlight. Perhaps someone with flash experience can answer.
浏览器(即 JavaScript)无法访问本地文件系统。 如果可以的话,这将是一场安全噩梦。
Browsers (i.e. JavaScript) cannot access the local file system, period. If they could, it would be a security nightmare.