import React, { Component } from 'react';
import {Button, Upload} from 'antd';
import { UploadOutlined } from '@ant-design/icons';
var fs = require('fs');
import CryptoJS from "crypto-js"
var FileSaver = require('file-saver');
class index extends Component {
getSha1=(value)=>{
let reader = new FileReader();
// 读取文件 value
reader.readAsArrayBuffer(value);
reader.onload = function () {
var wordArray = CryptoJS.lib.WordArray.create(reader.result);
var hash = CryptoJS.SHA1(wordArray).toString(); // 计算其他加密算法,SHA1改为MD5、SHA256即可
console.log('hash:', hash)
};
}
beforeUpload=(file)=>{
const fileList = [file]
this.getSha1(file)
}
render() {
return (
<div>
<Upload
beforeUpload={this.beforeUpload}
>
<Button type='primary' icon={<UploadOutlined />}>上传文件</Button>
</Upload>
</div>
);
}
}
export default index;