所有.
我的一切工作正常:图像正在上传,可以通过Web使用paperclip和S3访问,除非我登录rails c并键入以下内容:
> User.first.avatar.exists? [AWS S3 400 0.093287 0 retries] head_object(:bucket_name=>"mozg-staging-static",:key=>"users/avatars/000/000/001/original/289736.jpg") AWS::S3::Errors::BadRequest AWS::S3::Errors::BadRequest => false
我有这个许可政策:
{ "Sid": "Stmt1436958517000","Effect": "Allow","Action": [ "s3:AbortMultipartUpload","s3:DeleteObject","s3:DeleteObjectVersion","s3:GetBucketAcl","s3:GetBucketCORS","s3:GetObject","s3:GetObjectAcl","s3:GetObjectVersion","s3:GetObjectVersionAcl","s3:ListBucket","s3:ListBucketMultipartUploads","s3:ListBucketVersions","s3:ListMultipartUploadParts","s3:ListObjects","s3:PutObject","s3:PutObjectAcl","s3:PutObjectVersionAcl","s3:RestoreObject" ],"Resource": [ "arn:aws:s3:::mozg-staging-static","arn:aws:s3:::mozg-staging-static/*" ] }
谢谢你的支持.
解决方法
这可能是您的政策的问题,您可以尝试:
{ "Version": "2012-10-17","Statement": [ { "Effect": "Allow","Action": [ "s3:ListBucket" ],"Resource": ["arn:aws:s3:::mozg-staging-static"] },{ "Effect": "Allow","Action": [ "s3:PutObject","s3:DeleteObject" ],"Resource": ["arn:aws:s3:::mozg-staging-static/*"] } ] }
需要在存储桶级别设置ListBucket操作,而需要针对存储桶中的对象设置PutObject,GetObject和DeleteObject.我遗漏了其他行动以保持答案简短.如果需要,您当然需要重新添加它们.您可以在此处找到操作列表以及它们是桶操作还是对象操作:http://docs.aws.amazon.com/AmazonS3/latest/dev/using-with-s3-actions.html