上传文件转base64
function getBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
let fileResult = "";
reader.readAsDataURL(file);
// 开始转
reader.onload = () => {
fileResult = reader.result;
};
// 转 失败
reader.onerror = error => {
reject(error);
};
// 转 结束
reader.onloadend = () => {
resolve(fileResult);
};
});
}