【发布时间】:2014-05-11 11:43:35
【问题描述】:
我正在开发一个小型 Rails 站点,该站点允许一些用户上传图像,而其他用户则可以查看它们。我开始使用带有 S3 的 CarrierWave 作为存储介质,一切都很好,但后来我想尝试使用 CandFront。我首先在我的 S3 存储桶中添加了一个distribution,然后将我使用的 CarrierWave 配置更改为:
CarrierWave.configure do |config|
config.storage = :fog
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => ENV['S3_ACCESS_KEY_ID'], # required
:aws_secret_access_key => ENV['S3_SECRET_ACCESS_KEY'], # required
:region => 'eu-west-1',
}
config.asset_host = 'http://static.my-domain.com/some-folder'
config.fog_public = true # optional, defaults to true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
end
我应该提到http://static.my-domain.com 是一个指向 CloudFront 端点 (some-id.cloudfront.net) 的 CNAME 条目。结果是图片显示正确,URL 如下所示:http://static.my-domain.com/some-folder/uploads/gallery_image/attachment/161/large_image.jpg 但每当我尝试上传照片或获取上传附件的大小时,都会出现以下异常:
Excon::Errors::MovedPermanently: Expected(200) <=> Actual(301 Moved Permanently)
response => #<Excon::Response:0x007f61fc3d1548 @data={:body=>"",
:headers=>{"x-amz-request-id"=>"some-id", "x-amz-id-2"=>"some-id",
"Content-Type"=>"application/xml", "Transfer-Encoding"=>"chunked",
"Date"=>"Mon, 31 Mar 2014 21:16:45 GMT", "Connection"=>"close", "Server"=>"AmazonS3"},
:status=>301, :remote_ip=>"some-ip"}, @body="", @headers={"x-amz-request-id"=>"some-id",
"x-amz-id-2"=>"some-id", "Content-Type"=>"application/xml",
"Transfer-Encoding"=>"chunked", "Date"=>"Mon, 31 Mar 2014 21:16:45 GMT",
"Connection"=>"close", "Server"=>"AmazonS3"}, @status=301, @remote_ip="some-ip"
只是为了添加更多信息,我尝试了以下方法:
- 删除区域条目
- 直接使用 CloudFront URL 而不是 CNAME
- 指定 Amazon 端点 (
https://s3-eu-west1.amazonaws.com)
但它们都没有效果。
是我遗漏了什么还是 CarrierWave 目前不支持此功能?
【问题讨论】:
标签: ruby-on-rails carrierwave amazon-cloudfront