因为无法将文件上传到 Heroku 应用程序。
我正在为图像使用 Amazon S3 存储服务器。
问题只是图像 url 指向 Amazon S3 服务器。
我希望它是 mydomain.com/myimage.png
而不是 s3.amazon.com/bucket/myimage.png
访问示例时如何在 amazon s3 服务器上显示图像:mydomain.com/myimage.png
?
最佳答案
我的解决方案,我只使用 png 图像:
在 route :
match "/images/vind/:style/:id/:basename.png" => "public#image_proxy"
在公共(public) Controller 中:
def image_proxy
image_url = "http://s3-eu-west-1.amazonaws.com/konkurrencerher#{request.path}"
response.headers['Cache-Control'] = "public, max-age=#{84.hours.to_i}"
response.headers['Content-Type'] = 'image/png'
response.headers['Content-Disposition'] = 'inline'
render :text => open(image_url, "rb").read,
end
关于ruby-on-rails - Rails - 是否可以为外部图像提供本地 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9945690/