开发者

How to get around IE8 32k limit on data:uri on base64 encode?

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)


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.


You could always break apart the image into 4 (or more) and encode each section separately.


Couldn't you just store the image somewhere, return its path, and then change src to the path you just generated?


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)

<b><%= ('&lt;img src="data:image/jpg;base64,%s">' % Base64.encode64(@chart.to_blob)).html_safe %></b>

In Rails views: (Supports all browsers)

<b><%= image_tag @chart+".png" %></b>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜