我尝试使用Carrierwave(Rails 4.2上的1.0.0)将图像上传到S3。我得到403 Access Denied。但是,当我使用curl执行手动PUT
请求时,它可以正常工作。我已经确认Rails正在正确阅读我的秘密。所有这些对我来说意味着Excon在某种程度上不会发送我的凭据。
我该怎么办?
工作curl命令:
$ file=airplane.jpg
$ bucket=mybucket
$ resource="/${bucket}/${file}"
$ contentType="image/jpeg"
$ dateValue=`date -R`
$ stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
$ s3Key=redacted:)
$ s3Secret=redacted:)
$ signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
$ curl -X PUT -T "${file}" \
> -H "Host: ${bucket}.s3.amazonaws.com" \
> -H "Date: ${dateValue}" \
> -H "Content-Type: ${contentType}" \
> -H "Authorization: AWS ${s3Key}:${signature}" \
> https://${bucket}.s3.amazonaws.com/${file}
Carrierwave配置:
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: secrets[:aws_access_key_id],
aws_secret_access_key: secrets[:aws_secret_access_key],
region: 'eu-west-1',
host: 's3-eu-west-1.amazonaws.com'
}
config.fog_provider = 'fog/aws'
config.storage :fog
config.fog_directory = 'mybucket'
config.fog_public = true
config.fog_attributes = { 'Cache-Control' => 'max-age=315576000' }
编辑:更新 - 我不知道我改变了什么,但突然间使用curl命令时出现以下错误:
<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message></Error>
答案 0 :(得分:0)
这最终归结为S3配置错误。我不再记得确切的细节。