I have a Rails 3 app where I’m trying to display a page with users and their respective Skype status. This is easy to do if the page is HTTP: just set a background url of an element to the image returned from http://mystatus.skype.com/mediumicon/USERNAME.
However, my site is HTTPS, and loading resources via HTTP from an HTTPS causes IE to choke. And Skype evidently doesn’t provide an HTTPS version of the status icon.
So I’m taking the approach of getting the Skype status server-side (i.e. in the controller) by calling the above URL with Net::HTTP. Then I can write JUST the image bytes back to the page without a problem using send_data(). But I can’t figure out how to stream the image bytes back to the view along with all the other page data.
Any ideas?
Here is a code snippet that works. I have done it in sinatra purely to make it work stand alone, but the contents of the get block are the important lines.
This takes advantage of base64 encoding the source. You can read more here.
Please note that this may not work on older versions of IE.
One solution for this would be to base64 encode the image returned as above and to store all the images possible as a status and then do a comparison from the result. Obviously this would be quite slow doing it each time, so you would want to store the base64 of the images locally and then do a lookup on the base64 string.
Hope this makes sense.
EDIT
As a helper method: