Install the plug-in import CryptoJs from 'crypto-js'; //Quote AES source code js
package code
// md5值计算
export function fileToMd5(file: Blob) {
return new Promise((resolve) => {
const fileReader = new FileReader();
fileReader.onloadend = (ev) => {
resolve(CryptoJs.MD5(CryptoJs.enc.Latin1.parse(ev.target.result)).toString(CryptoJs.enc.Hex));
};
fileReader.readAsBinaryString(file);
});
}
Scenario: The front-end uploads a file to the cloud server, and compares the md5 value of the file stored in the back-end with the resource downloaded by the client. If it is different, it is not the latest resource.