You’d think it would be easy to send an image to a client with a framework as wonderful as Rails.
After doing quite a bit of searching for the simple way, I really didn’t turn up too much. Finally, I decided I would just open the file and write it out the old fashioned way: using the File object.
Got that all done, but for some reason my content-type in the header wasn’t getting properly picked up so the receiving browser was thinking it was something to save to my desktop. A quick look to make sure that my syntax was correct and there it was…
send_file(path, options={})
So, yeah. To have your controller send an image back:
send_file ‘/the/path/image.png’
Pretty tough
Advertisement