我试图在我的Rails应用程序中使用Carrierwave和Amazon S3,并且我一直收到错误
"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.
我也收到警告
"[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"
配置/初始化/ 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
我的水桶名称是“buildinprogress”
我已经仔细检查过我的访问密钥ID和访问密钥是否正确。
如何修复此错误?
答案 0 :(得分:4)
Fog / Excom的一个问题是我一直在为我抛出随机错误。
我的解决方法是删除 gem'fall',并将其替换为 gem'carminwave-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页面