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);
};
});
}
标签:文件,reject,base64,file,reader,new,上传,fileResult
From: https://www.cnblogs.com/tn666/p/17358027.html