简体   繁体   中英

Is there an efficient way to generate an MD5 hash of a browser Array Buffer?

I'm working on a strategy for uploading files to an API from a web application. The API needs an MD5 hash of the files sent along with the file. I believe the intent here is that they will then generate an MD5 on their side and compare the two to see if the file contents made it to the server without any lost data or changes.

I can generate the MD5 by using the file reader API to readAsText or readAsBinaryData and then run the contents through an MD5 algorithm.

My problem is that many of these are specialized imaging files that range from 10mb to 500mb in size. Trying to read those as binary or text is taking minutes and sometimes crashing the browser.

Using readAsArrayBuffer seems to be much more performant in terms of the read but I can't find a strategy for generating an MD5 that isn't as equally resource intensive as using readAsText.

So, is there a lightweight strategy for generating a MD5 from an Array Buffer? And maybe the real question is, is there a better way to verify that a file has made it from client to server without interruption? I don't have control over the API but can suggest changes.

1) What about CRC32 vs MD5?

2) SparkMD5 can hash incrementaly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM