Rails error paperclip `AWS :: S3 :: Errors :: BadRequest` on` exist? `And` clear`

everything.

Everything works fine for me: images are uploaded and can be accessed via the Internet using paperclip and S3, except when I enter rails c and type something like this:

 > 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 

The same thing happens with the clear method. No solution found yet.

I have this permissions policy:

  { "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/*" ] } 

Thank you for your support.

+8
ruby-on-rails amazon-s3 amazon-web-services paperclip
source share
1 answer

This may be a problem with your policy, can you try:

 { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:ListBucket" ], "Resource": ["arn:aws:s3:::mozg-staging-static"] }, { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObject", "s3:DeleteObject" ], "Resource": ["arn:aws:s3:::mozg-staging-static/*"] } ] } 

The ListBucket action must be set at the bucket level, while PutObject , GetObject and DeleteObject must be set against objects in the bucket. I left the other steps to answer a short question. Of course, you will need to add them back if necessary. You can find a list of actions and whether they are a bucket or object actions here: http://docs.aws.amazon.com/AmazonS3/latest/dev/using-with-s3-actions.html

0
source share

All Articles