【问题标题】:Internet Explorer - The data area passed to a system call is too small - Downloading png with the uriInternet Explorer - 传递给系统调用的数据区域太小 - 使用 uri 下载 png
【发布时间】:2017-11-02 02:16:32
【问题描述】:

我正在尝试使用 uri(下面的代码)下载 png 文件。它可以在 Chrome、Firefox 和 Safari 中运行——但(当然)不能在 Internet Explorer 中运行。我在 Windows 7 上,所以我在边缘文档模式下使用 IE11。错误是“传递给系统调用的数据区域太小”。我读过this MDN post

IE9 及更高版本以及 Edge 支持 CSS 和 JS 中的数据 URI 文件,但不是 HTML 文件,最大大小为 4GB。

我的 URI 只有 1410 字节(使用 uri.length)。任何想法为什么我会收到这种大小的数据错误以及如何解决它?

下载功能:

function downloadURI(uri, name) {
    var link = document.createElement("a");
    link.download = name;
    link.href = uri;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
    delete link;
}   

uri 格式:

"data:image/png;base64,iVBORw0KGgo ETC..."

【问题讨论】:

  • delete link; -> delete operator: “任何用 var 声明的属性都不能从全局作用域或函数作用域中删除。”
  • @Andreas - 我试过 => if (navigator.msSaveBlob) { return navigator.msSaveBlob(new Blob([uri], {type: "image/png"}), name);} 它下载得很好,但文件无法读取为 PNG。有什么建议吗?
  • 不,刚刚找到链接,看起来很有希望:|
  • 尝试将data:text/html,Hello folks 粘贴到地址栏中 - 它在 Firefox 和 Chrome 中有效,但在 IE 中无效。对于 PNG 图像的简短有效数据 URI,结果相同。 IE 似乎无法导航到数据 URI。

标签: javascript internet-explorer png uri


【解决方案1】:

解决方案如下。我似乎无法找到给予信用的链接,但这解决了它。我没有先将画布转换为 uri,而是通过画布并转换为 uri 并使用链接下载,或者(对于 IE)我转换为 blob 并使用 canavas.msToBlob() 和 msSaveBlob()

function downloadURI(canvas, name) {
  if (navigator.msSaveBlob) { // IE10+
    var blob = canvas.msToBlob();
    return navigator.msSaveBlob(blob, name);
  } else {
    var uri = canvas.toDataURL("image/png")
    var link = document.createElement("a");
    link.download = name;
    link.href = uri;
    document.body.appendChild(link);
    if (link.click) {
      link.click();
    } else {
      var event = document.createEvent('MouseEvents');
      event.initMouseEvent('click', true, true, window);
      link.dispatchEvent(event);
    }
    document.body.removeChild(link);
  }
}

【讨论】:

    猜你喜欢
    • 2012-10-22
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多