2017-05-04 35 views
0

S3にファイルをアップロードするためのオプションを検討しました。 S3静的なWebホスティングを使用して見ている1つのオプション。このオプションでは、アップロードオプション付きの単純なIndex.htmlページを作成しようとしているページがあります。私は、次のバケットポリシーを設定します。AWS S3静的ウェブホスティングを使用してS3にファイルをアップロード

{ 
    "Version": "2012-10-17", 
    "Statement": [ 
     { 
      "Sid": "Allow Public Access to All Objects", 
      "Effect": "Allow", 
      "Principal": "*", 
      "Action": [ 
       "s3:GetObject", 
       "s3:PutObject" 
      ], 
      "Resource": "arn:aws:s3:::<bucketname>/*" 
     } 
    ] 
} 

次は、CORS設定です:

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

私はS3にアクセスしようとすると、次のIndex.htmlと

<html> 
<header><title>Hello World</title></header> 
<body> 
Hello world 

<form action="/action_page.php"> 
    <input type="file" name="pic" accept="image/*"> 
    <input type="submit"> 
</form> 
</body> 
</html> 

のコードですウェブホスティングURIを持つバケット、私はページを取得しています。ドキュメントをアップロードしようとすると、次のエラーが表示されます。

404 Not Found 

Code: NoSuchKey 
Message: The specified key does not exist. 
Key: action_page.php 
RequestId: <requestid> 
HostId: <hostid> 
An Error Occurred While Attempting to Retrieve a Custom Error Document 

Code: NoSuchKey 
Message: The specified key does not exist. 
Key: error.html 

エラーページを表示するerror.htmlページを追加するとエラーページが表示されます。

これで、S3 Webホスティングを使用してファイルをバケットにアップロードすることは、コーディングなしで正しい方法ですか?私はここで何が欠けていますか?

答えて

1

S3静的WebサイトでPHPファイルを実行することはできません。バックエンドサーバーが必要なため、フォームは「action_page.php」に投稿しようとしています。

これは単純に機能しません。ここで

は、あなたが進むかもしれない方法の一例です:

In this example, a simple HTML page provides a browser-based application for creating photo albums in an Amazon S3 bucket into which you can upload photos. The application lets you delete photos and albums that you add.

http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-photo-album.html

関連する問題