In my Vuejs front-end, there is a file upload button. When user selected the file Vuejs triggers the @change event.I have used the file reader and I have imported the Cryptojs libraries which I have downloaded as node modules(in npm).
import cryptoJs from '../../node_modules/crypto-js'
import md5 from '../../node_modules/crypto-js/md5'
My html code for file upload button as follows:
<input type="file" ref="uploadedfile" name="file1" id="file1" @change="handleFileUpload">
File reader code inside the @change function:
handleFileUpload(e){
const filesToRead = e.target.files;
//getting the first file from the files array
let file1 = filesToRead[0];
const fileReader = new FileReader();
fileReader.addEventListener('loadend', (evt) => {
if (evt.target.readyState == FileReader.DONE) {
file1 = fileReader.result;
const encryptedvalue = md5(cryptoJs.enc.Latin1.parse(file1)).toString();
console.log("MD5 value is :");
console.log(encryptedvalue);
}
});
}
But always I get the same md5 value although I selected different files.
In the file object array, I can see all the file related data also when I inspect through the Chrome developer tool's console.(If I console log as follows)
console.log(file1);