2017-02-26 50 views
0

當在S3上讀取文件時產生錯誤Access Denied。設置回形針:當使用回形針將文件上傳到亞馬遜時讀取時拒絕訪問

has_attached_file :doc, 
       storage:  :s3, 
       s3_permissions: "public-read", 
       bucket: "my-app", 
       path:   ':message_subscriber/:class/:id_partition/:filename' 

我得到的網址,以便:@model.doc.url

如何解決讀取參數public-read

回答

1

確保在您的配置中設置了AWS access_key_idsecret_access_key。而且,您還需要確保您的用戶帳戶在AWS IAM控制檯中設置了Access Policy

詳情visit

這一政策爲我工作

{ 
    "Version": "2008-10-17", 
    "Statement": [ 
     { 
      "Effect": "Allow", 
      "Principal": { 
       "AWS": "arn:aws:iam::IAM_USER_ID:user/IAM_USER_NAME" 
      }, 
      "Action": [ 
       "s3:PutObject", 
       "s3:DeleteObject", 
       "s3:PutObjectAcl" 
      ], 
      "Resource": "arn:aws:s3:::S3_BUCKET_NAME/*" 
     } 
    ] 
} 
+0

我有AWS'access_key_id'和'secret_access_key'。在另一個項目中,我使用了這些設置而沒有制定政策。這裏不起作用。爲什麼不? – Andy

+0

您需要通過創建策略來授予對存儲器的訪問權限。瞭解它如何運作http://docs.aws.amazon.com/AmazonS3/latest/dev/using-with-s3-actions.html –

相關問題