我們一直在尋找上傳文件到S3的選項。我們正在使用S3靜態網頁寄存的一個選項。在這個選項中,我們將有一個頁面,我正嘗試用一個上傳選項編寫一個簡單的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>
下面是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>
代碼當我嘗試訪問我的S3桶與網站主辦的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 webhosting上傳文件到存儲桶沒有任何編碼是正確的方式?我在這裏錯過了什麼?