0

簡単な写真アップロードサービスをS3バケットに導入するには、this tutorialに従っています。 403 POSTからS3バケットに禁止

は私が許可されたすべてのAWSのユーザーのリストを付与し、次の方針

{ 
    "Version": "2012-10-17", 
    "Statement": [ 
     { 
     "Effect": "Allow", 
     "Action": [ 
      "s3:*" 
     ], 
     "Resource": [ 
      "arn:aws:s3:::BUCKET_NAME/*" 
     ] 
     } 
    ] 
} 

で新しい役割を作成し、バケット内の読み取り/書き込みアクセスを、

<?xml version="1.0" encoding="UTF-8"?> 
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> 
    <CORSRule> 
     <AllowedOrigin>*</AllowedOrigin> 
     <AllowedMethod>POST</AllowedMethod> 
     <AllowedMethod>GET</AllowedMethod> 
     <AllowedMethod>PUT</AllowedMethod> 
     <AllowedMethod>DELETE</AllowedMethod> 
     <AllowedMethod>HEAD</AllowedMethod> 
     <AllowedHeader>*</AllowedHeader> 
    </CORSRule> 
</CORSConfiguration> 

が新しいCognito生成され、次のCORSを設定上記のリンクでスクリプトを実行しました。私は、生成されたリンクにアクセスしようとすると

BUCKET_NAME.amazonaws.com/ALBUM_NAME//PHOTO_NAME.jpeg?uploads:1 POST https://BUCKET_NAME.amazonaws.com/ALBUM_NAME//PHOTO_NAME.jpeg?uploads 403 (Forbidden) 

:それは新しいアルバムを開き、私はS3コンソールでそれを見ることができますが、私は、アルバムに写真をアップロードしようとすると、私はエラーを取得し、正常に実行されスクリプトによって、私はこのXMLを得ます:

<Error> 
<Code>InvalidRequest</Code> 
<Message> 
Key is not expected for the GET method ?uploads subresource 
</Message> 
<RequestId>******</RequestId> 
<HostId> 
****** 
</HostId> 
</Error> 

なぜこの問題が発生するのでしょうか?

+0

、私は中に二重スラッシュを参照してください。 'ALBUM_NAME // PHOTO_NAME.jpeg'を。余分なスラッシュのためにスクリプトで渡しているパラメータをチェックし、削除してからやり直してみることをお勧めします。 – Aditya

+0

@Adityaこれは、スクリプトに表示される方法ですが、その行をvar albumPhotosKey = encodeURIComponent(albumName)+ '/'に変更しようとしました。それはまだ存続しています。 –

答えて

1

HTTP PUTではなく、HTTP POSTを実行しています。キーを渡す場合は、PUTを使用することになっています。 POSTを実行する場合は、pageで説明されているように、本体にキーを渡す必要があります。

0

s3バケットの権限の一部が欠落しています。あなたのエラーメッセージに

In this example, you want to grant an IAM user in your AWS account access to one of your buckets, example bucket, and allow the user to add, update, and delete objects.

In addition to granting the s3:PutObject, s3:GetObject, and s3:DeleteObject permissions to the user, the policy also grants the s3:ListAllMyBuckets, s3:GetBucketLocation, and s3:ListBucket permissions. These are the additional permissions required by the console. For an example walkthrough that grants permissions to users and tests them using the console, see An Example Walkthrough: Using user policies to control access to your bucket.

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

http://docs.aws.amazon.com/AmazonS3/latest/dev/example-policies-s3.html

+0

残念ながら、これは助けにはなりませんでしたが、私のアップロードされたファイルのパラメータから "ACL: 'public-read'を削除していました。なぜこの問題が解決されたのか説明してください。 –

関連する問題