[英]Uncaught DOMException: Failed to execute 'readAsDataURL' on 'FileReader'
I have been task to create and upload image file but i am having issue with the blob and base64 items the Blob URL is working as expected but when i try to use a FileReader it is showing the item is busy reading blob.我的任务是创建和上传图像文件,但我遇到了 blob 和 base64 项目的问题,Blob URL 按预期工作,但是当我尝试使用 FileReader 时,它显示该项目正忙于读取 blob。 I have also tried to remove the code files for URL the retain the File Reader code but still same issues.
我还尝试删除 URL 的代码文件,保留文件阅读器代码,但仍然存在相同的问题。 And also how the onload is called every time how to stop it after the base64 is created.
以及每次在创建base64后如何停止它时如何调用onload。 Or is it also posible to convert the blob URL to a base64
或者也可以将 blob URL 转换为 base64
uploadImageChange(e){
const file = e.target.files[0];
this.showImageModalErrorMessage = false;
let fileReader = new FileReader();
fileReader.onload = function(fileLoad){
console.log(fileReader.readAsDataURL(file));
}
if(file.size < 2000){
this.imageSelectedUrl = URL.createObjectURL(file);
this.showImageSaveContent = true;
this.modalSecondInstruction = true;
}else{
this.imageModalErrorMessage = "The image you chose is bigger than 2 MB. Kindly upload a smaller-sized photo."
this.showImageModalErrorMessage = true;
}
},
Try this way试试这个方法
let fileReader = new FileReader();
fileReader.readAsDataURL(file);
fileReader.onload = function(fileLoad){
consoloe.log(fileReader.result);
}
Had a similar problem, the below code worked for me fine.有一个类似的问题,下面的代码对我来说很好。
fileReader(file: any) {
const reader = new FileReader();
reader.onloadend = () => {
const formData = new FormData();
const blobFile = new Blob([reader.result], { type: file.type });
formData.append("file", blobFile, "filename");
// POST formData call
};
reader.readAsArrayBuffer(file);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.