“啊,啪"当数据uri太大时 [英] "Aw, Snap" when data uri is too large
问题描述
我正在编写一个 chrome 扩展程序,它执行以下操作:
I'm writing a chrome extension which does the following:
- 使用
XMLHttpRequest
从网站下载文件到内存 - 向文件添加额外数据,然后将结果进行 base64 编码到变量
total_encoded_data
- 使用
点击下载
.其中- 向用户提供数据;/a>
total_encoded_data
使用 jQuery 添加到 href 中.
- Downloads a file from a website to memory using
XMLHttpRequest
- Adds additional data to the file and then base64 encodes the result to the variable
total_encoded_data
- 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>
. Wheretotal_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屋!