简体   繁体   English

IE10-base64编码的图像加载错误

[英]IE10 - base64-encoded image load error

After uploading 10-20 images (~2MB, one by one in the synchronous loop) IE throws an error during loading the image from base64 string. 上载10-20个图像(〜2MB,在同步循环中一个接一个)后,IE从base64字符串加载图像时会引发错误。 I have in my code something like this: 我的代码中有这样的内容:

var reader = new FileReader();
reader.onload = function (e) {
  var img = new Image();
  img.onload = function () { console.log('onload'); /* some simple work with canvas */ };
  img.onerror = function () { console.log('onerror'); };
  img.src = e.target.result;
};
reader.readAsDataURL(file);

IE throws an error after some time and do not want to load more images. IE会在一段时间后引发错误,并且不想加载更多图像。 I have tried to use setTimeout but without success. 我试图使用setTimeout但没有成功。

Any ideas why it happens? 任何想法为什么会发生?

Browsers can have some limitation on data URI size 浏览器可能对数据URI大小有一些限制

Try the URL.createObjectURL instead 试试URL.createObjectURL代替

var src = URL.createObjectURL(file);
var img = new Image();
img.onload = function () { 
    /* some simple work with canvas */ };
    URL.revokeObjectURL(src); 
    console.log('onload');
img.onerror = function () { console.log('onerror'); };
img.src = src;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何下载 base64 编码的图像? - How to download a base64-encoded image? IPFS:base64 编码的图像未显示为图像 - IPFS: base64-encoded image not showing as image 使用angularjs将SVG中的xlink:href设置为base64编码的图像 - Set xlink:href in svg with angularjs to base64-encoded image 上传到Google云端硬盘-如何使用base64编码的图像或图像路径 - Uploading to Google Drive - how to use a base64-encoded image or an image path 如何从 javascript 中的本地文件图像创建 base64 编码的字符串 - How to create a base64-encoded string from a local file image in javascript Sails.js如何将base64编码的图像转换为图像并将其存储在磁盘中? - Sails.js how to convert a base64-encoded to image and store it in disk? 对 base64 URI 支持的更好测试(我可以在 JS 中创建一个大的 base64 编码图像吗?) - A better test for base64 URI support (can I create a large base64-encoded image in JS?) 使用Java脚本删除Base64编码的URL参数 - Strip Base64-encoded URL parameters with Javascript base64编码的ajax损坏发送对此的一些想法 - Corruption of base64-encoded ajax sends -some thoughts on this 在Javascript中将PDF转换为Base64编码的字符串 - Convert PDF to a Base64-encoded string in Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM