[ACCEPTED]-Rails - How to send an image from a controller-open-uri

Accepted answer
Score: 48

Wouldn't be better to use send_file instead?

send_file Rails.root.join("public", "file.gif"), type: "image/gif", disposition: "inline"

0

Score: 17

Is there a reason that you cannot save the 5 file to public/_ctrack.gif, remove the route, and let the 4 underlying web server serve the image?

If 3 you need to process the image from disk, just 2 use open on the local filename:

send_data open("#{Rails.root}/path/to/file.gif", "rb") { |f| f.read } .......

The rb sets the 1 file to open and binary modes.

More Related questions