So this should be pretty easy, yet I can\'t get it work.
I have a controller method that finds an image based on a query, then the output gets cached. The image coul
What version of Rails? For Rails 3, you should look at the streaming methods that were added. send_data would be the proper way of sending binary data. If the images are local, and your web server supports it, you can use send_file which won't block a rails instance while the user downloads an image.
Try using render :text => open(image_url, "rb").read
, which tells Ruby that the file it opens is binary, and not to try reading it as text.
edit
For the bonus question, you could read the first few bytes and look at what they contain. A PNG will always start with the hexadecimal byte values 89 50 4E 47 0D 0A 1A 0A (or the decimal values 137 80 78 71 13 10 26 10).
Wikipedia has a list of magic numbers used to identify file that you can look at. Just create a method of some sort that reads the first few bytes and compares it to that.