Is there a way to calculate the MD5 of an image file on the client side within my Angular Map application, that will match the MD5 when I store the file on Firestore? I need to verify that a user's file matches a reference version stored in Firebase without having to re-upload it.
I can retrieve an array buffer from a local file object, but am struggling with performing the md5 calculation locally to get the same result as Firebase.
The outcome I obtained looks completely different from the md5 value provided by Firebase, indicating I may not be approaching this correctly:
let file = target.files[0];
let reader = new FileReader();
reader.onload = function (event) {
data = event.target.result;
let ret: any = data;
if (data) {
let len = ret.byteLength;
let uintArBuff = new Uint8Array(ret); //Can an array buffer convert to a Uint8Array?
let md5 = new Md5();
let hash = md5.appendByteArray(uintArBuff).end();
console.log(hash);
}
}
reader.readAsArrayBuffer(file);
The above code snippet generated a result resembling 29e10414c7c7b7adb61330b02f8f3ddc
, whereas
the MD5 reported by Firebase is KeEEFMfHt622EzCwL4893A==
. It seems like I may be heading in the wrong direction altogether. The hash lengths are not even matching...