“啊,啪"当数据uri太大时 [英] "Aw, Snap" when data uri is too large

查看:18
本文介绍了“啊,啪"当数据uri太大时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 chrome 扩展程序,它执行以下操作:

I'm writing a chrome extension which does the following:

  1. 使用 XMLHttpRequest
  2. 从网站下载文件到内存
  3. 向文件添加额外数据,然后将结果进行 base64 编码到变量 total_encoded_data
  4. 使用点击下载
  5. 向用户提供数据;/a>.其中 total_encoded_data 使用 jQuery 添加到 href 中.
  1. Downloads a file from a website to memory using XMLHttpRequest
  2. Adds additional data to the file and then base64 encodes the result to the variable total_encoded_data
  3. Offers the data to the user using <a href=data:application/octet-stream;charset=utf-8;base64,' + total_encoded_data+' download='file.bin'>Click to Download</a>. Where total_encoded_data is added to href using jQuery.

我通过手动二进制搜索发现,如果total_encoded_data 的大小大于2097100 个字符,那么当我单击链接时,我会收到一条Aw, Snap 消息.如果大小较小,那么我可以按预期下载.

I have found, through a manual binary search, that if the size of total_encoded_data is greater than 2097100 characters, then I will get an Aw, Snap message when I click the link. If the size is smaller, then I can download as expected.

除了测试文件大小之外,我还使用了atoi来确保base64编码有效,并且运行无误.

In addition to testing the filesize, I also used atoi to ensure that the base64 encoding is valid, and it operates without error.

The Aw, Snap 消息不会在 chrome://crashes 中产生任何崩溃报告,也不会在 chrome_debug.log

The Aw, Snap messages don't produce any crash reports in chrome://crashes nor any unexpected output in the chrome_debug.log

在提供 base64 编码字符串长度大于 2097100 的数据 uri 时,如何避免出现 Aw, Snap 消息?

How do I avoid an Aw, Snap message when serving a data uri where the base64 encoded string length is greater than 2097100?

推荐答案

这是一个 已知的铬错误.推荐的解决方法是使用 blob URL.另请参阅 从 base64 字符串创建 BlobJavaScript.

It's a known chromium bug. The recommended workaround is to use a blob URL. Also see Creating a Blob from a base64 string in JavaScript.

这篇关于“啊,啪"当数据uri太大时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆