javascriptextjs

how to get file MD5 from FileReader readAsArrayBuffer()


anyone know how to get file MD5 from Filereader readAsArrayBuffer() ?

my current solution is using CryptoJS

  1. convert arraybuffer to base64
  2. decode base64 to binary string.
  3. use CryptoJS.MD5(p_str).toString(CryptoJS.enc.Hex).toUpperCase();

this method get me correct MD5 but I hope to skip the part decode the base64. the suggestions I found is using readAsBinaryString() which deprecated function.


Solution

  • thanks. someone suggest sparkmd5 which calculate md5 from array buffer which is working.

    SparkMD5.ArrayBuffer.hash(e.target.result)