如何绕过 IE8 对 data:uri Base64 编码的 32k 限制?
我需要向浏览器发送包含 1920x1080 png 的 html 响应。这是一个 html 查询截取的屏幕截图。
我对图像进行 base64 编码,并将其作为 text/html 内容类型嵌入发送。一些简单的事情,比如:
<HTML><HEAD>Whatever</HEAD><BODY><img src="data:image/png;base64,data"/></BODY></HTML>
它在 FF 和 Chrome 上运行良好,问题是我需要支持 IE8。 IE8对data:uri的长度有限制。
如果我压缩图像,使 png 编码低于 32k(大约 600x500),我会丢失太多信息。
解决这个问题最简单的方法是什么? (我无权访问服务器来托管图像等)
I need to send an html response to the browser containing a 1920x1080 png. It's a screenshot taken by an html query.
I encode the image in base64 and sends it embedded as an text/html content-type. Something simple like :
<HTML><HEAD>Whatever</HEAD><BODY><img src="data:image/png;base64,data"/></BODY></HTML>
It works fine on FF and Chrome, the problem is I need to support IE8. IE8 as a limit on the length of the data:uri.
If I compress the image so the png encoding is under 32k (about 600x500) I lose too much information.
What would be the easiest work around for this problem? (I don't have access to a server to host the image or such)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最终我们放弃了对 IE8 的支持。
我很幸运它仅用于内部调试目的。
但问题仍然存在。希望 IE9 不会有 data:uri 限制。
In the end we dropped IE8 support.
I'm lucky it's for internal debugging purpose only.
The problem still stand though. Hopefully IE9 won't have data:uri limit.
您始终可以将图像分成 4 个(或更多)并分别对每个部分进行编码。
You could always break apart the image into 4 (or more) and encode each section separately.
难道你不能将图像存储在某个地方,返回其路径,然后将 src 更改为你刚刚生成的路径吗?
Couldn't you just store the image somewhere, return its path, and then change src to the path you just generated?
Base64 编码的数据 URI 在版本大于或等于 9 的 IE 中工作正常。由于 IE 9 没有数据 URI 限制。我还尝试修复此 IE 8 问题。但我无法解决这个问题。为了解决这个问题,将图像存储在应用程序内部的某个位置每当显示它时,从应用程序中检索它。
在 Rails 视图中:(如果 IE >=9 则支持)
在 Rails 视图中:(支持所有浏览器)
Base64 encoded data URI is working fine in IE whose version is greater than or equal to 9. Since there is no data URI limitation for IE 9. Also I tried to fix this IE 8 issue. But I couldn't able to fix this issue. For Work around,storing images in somewhere inside your application & retrieve it back from application whenever displaying it.
In Rails views: (supports if IE >=9)
In Rails views: (Supports all browsers)