Rails - How to send an image from a controller

不想你离开。 提交于 2019-12-02 17:37:31

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

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

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

The rb sets the file to open and binary modes.

Wouldn't be better to use send_file instead?

send_file Rails.root.join("public", "file.gif"), type: "image/gif", disposition: "inline"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!