Ruby on rails Rails-是否可以为外部图像提供本地url?

Ruby on rails Rails-是否可以为外部图像提供本地url?,ruby-on-rails,ruby,ruby-on-rails-3,Ruby On Rails,Ruby,Ruby On Rails 3,因为无法将文件上载到Heroku应用程序 我正在使用AmazonS3存储服务器来存储图像 问题只是图像url指向AmazonS3服务器 我希望它是mydomain.com/myimage.png而不是s3.amazon.com/bucket/myimage.png 访问示例:mydomain.com/myimage.png时,如何在AmazonS3服务器上显示图像 您可以创建一个机架中间件,该中间件将在url(/images/*或*.png)中查找模式,当存在匹配时,它将充当代理,从S3请求图像

因为无法将文件上载到Heroku应用程序

我正在使用AmazonS3存储服务器来存储图像

问题只是图像url指向AmazonS3服务器

我希望它是
mydomain.com/myimage.png
而不是
s3.amazon.com/bucket/myimage.png


访问示例:
mydomain.com/myimage.png
时,如何在AmazonS3服务器上显示图像

您可以创建一个机架中间件,该中间件将在url(/images/*或*.png)中查找模式,当存在匹配时,它将充当代理,从S3请求图像并为其接收的内容提供服务


确保将缓存头设置正确,以便Heroku的反向代理将缓存它并快速提供服务。

我的解决方案,我只使用png图像:

路线:

match "/images/vind/:style/:id/:basename.png" => "public#image_proxy"
在公共控制器中:

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