Page 1 of 1

Generate file checksum client-side

Posted: Mon May 24, 2010 1:10 pm
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. :)

Re: Generate file checksum client-side

Posted: Mon May 24, 2010 1:20 pm
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/

Re: Generate file checksum client-side

Posted: Mon May 24, 2010 1:30 pm
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.

Re: Generate file checksum client-side

Posted: Mon May 24, 2010 4:07 pm
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?)

Re: Generate file checksum client-side

Posted: Mon May 24, 2010 4:46 pm
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.