“Aw,Snap”当数据uri太大时 [英] "Aw, Snap" when data uri is too large
问题描述
- 使用<$ c $将文件从网站下载到内存中c> XMLHttpRequest
- 向文件添加额外的数据,然后base64将结果编码到变量
total_encoded_data
- 使用
< a href = data:application / octet-stream; charset = utf-8; base64,'+ total_encoded_data +'下载向用户提供数据='file.bin'>点击下载< / a>
。使用jQuery将total_encoded_data
添加到href。
我发现如果 total_encoded_data
的大小大于2097100个字符,则当我单击该链接时,我将收到一条Aw,Snap消息。如果尺寸较小,那么我可以按预期下载。除了测试文件大小外,我还使用 atoi
来确保base64编码是有效的,并且它
Aw,Snap消息不会在 chrome:// crashes
中产生任何崩溃报告,在 chrome_debug.log
中没有任何意外的输出,如何在提供数据时避免发送Aw,Snap消息uri其中base64编码的字符串长度大于2097100?
这是一个已知的铬错误。建议的解决方法是使用 blob网址 。另请参阅从base64字符串创建Blob JavaScript 。
I'm writing a chrome extension which does the following:
- 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.
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.
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 messages don't produce any crash reports in chrome://crashes
nor any unexpected output in the chrome_debug.log
How do I avoid an Aw, Snap message when serving a data uri where the base64 encoded string length is greater than 2097100?
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.
这篇关于“Aw,Snap”当数据uri太大时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!