Carrierwave - 为Amazon S3配置

时间:2014-09-03 07:09:29

标签: ruby-on-rails amazon-s3 carrierwave fog

我有一个Rails 4应用程序,我正在尝试配置Carrierwave和Fog以在Amazon S3上存储上传的文件,但我不断收到以下错误:

Expected(200) <=> Actual(301 Moved Permanently) excon.error.response :body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>PermanentRedirect</Code><Message>The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.</Message><RequestId>3C27ACF693820E4E</RequestId><Bucket>bucket_name</Bucket><HostId>8hnHAWoVEgsGkSyclME99rPTq5UHuSt6ZQ/ezmCRcuK+JUGWsSeI4FvcC2A5cym7</HostId><Endpoint>s3.amazonaws.com</Endpoint></Error>" :headers => { "Content-Type" => "application/xml" "Date" => "Wed, 03 Sep 2014 06:59:16 GMT" "Server" => "AmazonS3" "x-amz-id-2" => "8hnHAWoVEgsGkSyclME99rPTq5UHuSt6ZQ/ezmCRcuK+JUGWsSeI4FvcC2A5cym7" "x-amz-request-id" => "3C27ACF693820E4E" } :local_address => "10.0.0.9" :local_port => 54480 :remote_ip => "176.32.114.26" :status => 301

配置/初始化/ carrierwave.rb:

CarrierWave.configure do |config|
  config.fog_credentials = {
  :provider               => 'AWS',
  :aws_access_key_id      => 'XXXXXXXXXXXXXXXXXXXX',
  :aws_secret_access_key  => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  :region                 => 'us-east-1'
}
config.fog_directory  = 'bucket_name'
config.fog_public     = false
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end

我也尝试删除:region参数(以及前面的逗号),但这似乎也不起作用。我检查了桶区域,它被列为“美国标准”但如果我查看端点,亚马逊将该桶列为us-east-1。无论如何,我已经尝试将这两个值分配给:region并且都没有工作。

有人可以帮我弄清楚我做错了吗?

1 个答案:

答案 0 :(得分:1)

如果这可能有助于某人节省几个小时的生命,解决方案结果是我只需要在修改文件后重新启动服务器。