Send an image

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


Leave a comment

Filed under rails, Ruby

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s