# Displaying Base64binary encoded images

**URL:** <https://www.ruby-forum.com/t/displaying-base64binary-encoded-images/138658>\
**Category:** Rails\
**Created:** [May 26, 2008, 12:27pm UTC](https://www.ruby-forum.com/t/displaying-base64binary-encoded-images/138658 "2008-05-26T12:27:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [May 26, 2008, 12:27pm UTC](https://www.ruby-forum.com/t/displaying-base64binary-encoded-images/138658/1 "2008-05-26T12:27:21Z")

</div>

Hi,  
I am querying a webservice which returns images as Base64 encoded data.  
Displaying these images in Firefox is not a problem:  
 ![](data:image/jpeg;base64,<%=@image_data%>)

## However, I am having trouble displaying the images in Internet Explorer. I have been looking at the following page: [Dean Edwards: Base64 Encoded Images for Internet Explorer](http://dean.edwards.name/weblog/2005/06/base64-ie/) which uses a regular expression in Javascript to identify any Base64 images and then uses a PHP function to decode the data and display it correctly Internet Explorer. I have been trying to do the decoding of the data in the controller (rather than having to use the Javascript & PHP method) but I can’t get it to work:

Controller:  
require ‘base64’  
@image\_data =  
“R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==”

# This is Base64 encoded

@image\_data\_decoded = decode64(@image\_data)

## View: ![]()

@image\_data\_decoded is a binary string that does work correctly when  
passed to the view.  
What i am doing wrong?  
Thanks

---

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [May 26, 2008, 1:32pm UTC](https://www.ruby-forum.com/t/displaying-base64binary-encoded-images/138658/2 "2008-05-26T13:32:02Z")

</div>

On 26 May 2008, at 11:27, Tim C. wrote:

> ![]()

You can’t just sling binary data into the html like that. If you look  
at what the web page you mentionned is doing, what it does is rewrite  
the img tags so that they point at some action on your server. that  
action then serves up the decoded image (in rails you would use  
send\_data)

Fred
