Generate file checksum client-side

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Generate file checksum client-side

Post by Chalks »

I don't think this post properly belongs in the JS forum, but I'm not sure where else to put it.

When a user uploads a file, I generate a unique string for that file using hash_file(). I would like to be able to figure out what this string is without making my server do all the work. In other words, have the hash calculated client-side with JS (impossible, I think) or some other language (java?). I _could_ write a program in C++ to do it, but I don't particularly want to force my users to download a program just so they can upload files.

Any ideas where to start with this? Or, even better... an open source upload utility that has his ability built in?

Thanks. :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Generate file checksum client-side

Post by Christopher »

What algorithm are you using? There are several of these implemented in Javascript. I know there is a MD5 implementation. Search for them/
(#10850)
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: Generate file checksum client-side

Post by Chalks »

sha256. I already have a JS script that calculates the hash of a string using this algo. File access is a different beast though. As I understand it, there is no way for JS to access the actual file _before_ it is uploaded to the server.
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: Generate file checksum client-side

Post by kaszu »

As I understand it, there is no way for JS to access the actual file _before_ it is uploaded to the server.
Only in firefox at the moment (see getAsBinary http://hacks.mozilla.org/2009/06/xhr-pr ... -feedback/)
I guess flash has access to files before uploading them to server (flash file uploaders?)
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: Generate file checksum client-side

Post by Chalks »

and only the latest/greatest version of FF.

I've been looking around for this because there's a very high likelyhood that my users will be uploading the same files. If I can generate a checksum before they upload it, I can check if I already have the file on the server and save my users the hassle (and time) of uploading. I have literally 0 experience with flash... is it difficult to get into? Also, think that you could do something like this with java? I'm certainly more comfortable coding with that.
Post Reply