//文件转base64 function toDataURL(url) { fetch(url) .then(response => response.blob()) .then(blob => new Promise((resolve, reject) => { const reader = new FileReader() reader.onloadend = () => resolve(reader.result) reader.onerror = reject reader.readAsDataURL(blob) }));}//base64转File对象function base64ToFileObj(filePath, fileName) { toDataURL(filePath) .then(dataUrl => { console.log('RESULT:', dataUrl.length) //base64文本 const url = dataUrl; //base64转file对象 fetch(url) .then(res => res.blob()) .then(blob => { const file = new File([blob], fileName, { type: "image/png" }) //最终输出的文件对象 console.log('fileObj', file); }); })}