Rails - 是否可以为外部图像提供本地URL?

Rai*_*ner 4 ruby ruby-on-rails ruby-on-rails-3

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

我正在使用Amazon S3存储服务器来处理图像.

问题只是图像URL是到Amazon S3服务器的.

我希望它mydomain.com/myimage.png代替s3.amazon.com/bucket/myimage.png

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

Rai*_*ner 7

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

在路线:

match "/images/vind/:style/:id/:basename.png" => "public#image_proxy"
Run Code Online (Sandbox Code Playgroud)

在公共控制器中:

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
Run Code Online (Sandbox Code Playgroud)