我想使用FileReader将文件转换为base64格式。但是我收到了Uncaught TypeError错误。如何防止这种情况发生,如何将文件成功转换为base64格式?
控制台日志
[File]
0: File {_relativePath: "", name: "5-Defect-Management-Logs.docx", lastModified: 1576500873045, lastModifiedDate: Mon Dec 16 2019 15:54:33 GMT+0300 (GMT+03:00), webkitRelativePath: "", …}
length: 1
__proto__: Array(0)
PPP14.js:152 Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'.
at onupdatefiles (PPP14.js:152)
at options.onupdatefiles (react-filepond.js:80)
at exposeEvent (filepond.js:11728)
at filepond.js:11744
反应js
<div className="App">
<FilePond
onupdatefiles={(fileItems) => {
props.values.addendumA = fileItems.map(fileItem => fileItem.file)
console.log('addendumA instance has initialised',props.values.addendumA)
if(props.values.addendumA){
var reader = new FileReader();
reader.readAsDataURL(props.values.addendumA);
}
}
}
/>
</div>