i have a function getHash in which i am passing the file to get the hash.
function getHash(data) {
console.log(data);
const [file] = data;
console.log(file);
const reader = new FileReader();
let dataHash ;
reader.onload = () => {dataHash=md5(reader.result),console.log(dataHash)};
if (file) {
reader.readAsText(file);
}
console.log(dataHash);
return dataHash;
}
then i am calling it inside another function but how will i get the value of dataHash in the function in which i am calling it
FIRMWARE.uploadFiles = (body, index) => {
body.size += body.data[index].size;
let bodyData = body.data;
console.log(typeof (bodyData));
console.log(bodyData[1]);
let fileHash = [];
let hash = '';
getHash(bodyData);
// console.log(hash);
// fileHash.push(hash);
if (bodyData.length = 2) {
const dt = new DataTransfer();
dt.items.add(bodyData[1]);
getHash(dt.files);
}
//console.log(dataHash);
body['fileHash'] = fileHash;
i want the value of hash to be returned by getHash function in the below function