简体   繁体   English

未捕获的 DOMException:无法在“FileReader”上执行“readAsDataURL”

[英]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.

相关问题 未捕获的 DOMException:无法在“FileReader”上执行“readAsDataURL”:该对象已在忙于读取 Blob。(...) - Uncaught DOMException: Failed to execute 'readAsDataURL' on 'FileReader': The object is already busy reading Blobs.(…) 未捕获的类型错误:无法在“FileReader”上执行“readAsDataURL”:参数 1 的类型不是“Blob” - Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' Angular.js:未捕获的TypeError:无法在“ FileReader”上执行“ readAsDataURL”:参数1的类型不是“ Blob” - Angularjs : Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' 无法在&#39;FileReader&#39;上执行&#39;readAsDataURL&#39;:对象已经忙于读取Blob - Failed to execute 'readAsDataURL' on 'FileReader': the object is already busy reading Blobs 类型错误:无法在“FileReader”上执行“readAsDataURL”:参数 1 的类型不是“Blob” - TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' 有时会:无法在“FileReader”上执行“readAsDataURL”:参数 1 不是“Blob”类型 - Sometimes getting: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' 未捕获的 DOMException:无法在“历史”上执行“pushState”: - Uncaught DOMException: Failed to execute 'pushState' on 'History': 未捕获的 DOMException:无法在“节点”上执行“appendChild” - Uncaught DOMException: Failed to execute 'appendChild' on 'Node' 将博客转换为 base64:TypeError:无法在“FileReader”上执行“readAsDataURL”:参数 1 不是“Blob”类型 - Converting blog to base64: TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' 未捕获的 DOMException:无法在“HTMLCanvasElement”上执行“toDataURL”:可能无法导出受污染的画布 - Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM