We are currently planning a website on which people can upload movies. When looking at YouTube you notice that some movies are uploaded twice or more times (by different users). To scale our application we're thinking about the following idea:
- User selects movie file to be uploaded
- A JavaScript will get the SHA256 hash from the file (it's more accurate then the MD5 hash) before it get's uploaded
- The website will check if the hash already exists
- If the hash doesn't exist, the file will be uploaded
- If the hash does exist a message will be prompted or a reference to the already existing version on the server will be created. This without the video being uploaded.
Q: How do we analyze a file with JavaScript in order to get the SHA256 hash, and is SHA256 good enough or should we consider SHA512 (or another algorithm)?
We are currently planning a website on which people can upload movies. When looking at YouTube you notice that some movies are uploaded twice or more times (by different users). To scale our application we're thinking about the following idea:
- User selects movie file to be uploaded
- A JavaScript will get the SHA256 hash from the file (it's more accurate then the MD5 hash) before it get's uploaded
- The website will check if the hash already exists
- If the hash doesn't exist, the file will be uploaded
- If the hash does exist a message will be prompted or a reference to the already existing version on the server will be created. This without the video being uploaded.
Q: How do we analyze a file with JavaScript in order to get the SHA256 hash, and is SHA256 good enough or should we consider SHA512 (or another algorithm)?
Share Improve this question edited Dec 4, 2011 at 1:39 Peter O. 32.9k14 gold badges85 silver badges97 bronze badges asked Dec 4, 2011 at 1:29 Wouter DorgeloWouter Dorgelo 12k12 gold badges65 silver badges80 bronze badges 03 Answers
Reset to default 6Use the HTML5 File API to read the file: http://www.html5rocks./en/tutorials/file/dndfiles. Here is a JS code for calculating SHA-256: http://www.webtoolkit.info/javascript-sha256.html
I must add that I never tried this, but it seems to be possible. Alxandr is right, this would take very long for large videos, but you may try to use the WebWorker API in order not to freeze the browser: http://html5rocks./en/tutorials/workers/basics
Putting files aside for now, if the question is actually whether it's possible to get a SHA-256 hashes in JavaScript, the answer is yes. You can either reiplement this yourself (bad idea) or use a library like the Stanford JS Crypto library (good idea).
As far as the File API goes, it is implemented in the bleeding edge version of every major desktop browser, as well as the latest Android browser shipping. iOS is not supported as it doesn't really have a filesystem. Check out caniuse. for the latest stats.
Simple answer, you can't. That is if you want to support all browsers at least. I think both Chrome and FireFox supports the reading of files on the client, and IE supports it with the help of ActiveX controls, but to get a solution that works in all browsers you have to use a plugin like Flash or Silverlight. Also, when doing file-uploads of video-magnitude (large+ files), I think going for flash or the likes from the start is a good idea anyhow, but that's just my opinion.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745169719a4614850.html
评论列表(0条)