1

I am attempting to use Carrierwave with Amazon S3 in my Rails app, and I keep getting the error

"Excon::Errors::Forbidden (Expected(200) <=> Actual(403 Forbidden)."  
<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.

I also receive the warning

"[WARNING] fog: the specified s3 bucket name() is not a valid dns name, which will negatively impact performance.  For details see: http://docs.amazonwebservices.com/AmazonS3/latest/dev/BucketRestrictions.html"  

config/initializers/carrierwave.rb:

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider: 'AWS',                      
    aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
    aws_secret_access_key: ENV["AWS_ACCESS_KEY"]
  }
  config.fog_directory = ENV["AWS_BUCKET"]                
end

My bucket name is "buildinprogress"

I've double checked that my access key ID and access key are correct.

How can I fix this error??

4

1 回答 1

6

Fog/Excom 的问题也一直在为我抛出随机错误。

我的解决方法是删除gem 'fog'并将其替换为gem 'carrierwave-aws'

然后,在您的*_uploader.rb更改

storage :fog ---> storage :aws

并更新您的carrierwave.rb文件 例如:

  CarrierWave.configure do |config|
    config.storage    =  :aws                  # required
    config.aws_bucket =  ENV['S3_BUCKET']      # required
    config.aws_acl    =  :public_read

    config.aws_credentials = {
      access_key_id:      ENV['S3_KEY'],       # required
      secret_access_key:  ENV['S3_SECRET']     # required
    }

    config.aws_attributes = {
                              'Cache-Control'=>"max-age=#{365.day.to_i}",
                              'Expires'=>'Tue, 29 Dec 2015 23:23:23 GMT'
                            }
  end

有关更多信息,请查看carrierwave-aws GitHub 页面

于 2015-02-06T21:27:49.417 回答