I am using a react
module called react-dropzone
. When the user drops a file, it returns a File
, which is a type of blob
.
My goal is to find the sha-256 hash of this file. To do this I am trying to take the File
, convert it into a buffer
then feed the buffer
to the crypto
module. Here is the code I am using:
handleOnDrop = file => {
var fileReader = new FileReader();
fileReader.onload = event => {
this.externalScopeVariable = event.target.result;
};
const buffer = fileReader.readAsArrayBuffer(file);
hash.update(buffer);
console.log(hash.digest("hex"));
});
};
I am getting the error, TypeError: Cannot read property 'length' of undefined
coming from the sha.js
node module.
Any help on how to accomplish the task of successfully hashing the File
is a huge help. Thanks