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

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

问题描述


  1. 使用<$ c $将文件从网站下载到内存中c> XMLHttpRequest

  2. 向文件添加额外的数据,然后base64将结果编码到变量 total_encoded_data

  3. 使用< 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:

  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.

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屋!

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