[ACCEPTED]-Rails - How to send an image from a controller-open-uri
Accepted answer
Wouldn't be better to use send_file instead?
send_file Rails.root.join("public", "file.gif"), type: "image/gif", disposition: "inline"
0
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.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.