我们一直在寻找上传文件到 S3 的选项。我们正在考虑使用 S3 静态 Web 托管的选项。在此选项中,我们将拥有一个页面,我正在尝试编写一个简单的 Index.html 页面并添加上传选项。我设置了以下存储桶策略:
{
"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>
当我尝试使用Web托管URI访问我的s3存储桶时,可以打开页面,但在上传文档时出现以下错误:
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上传文件到存储桶中,而不需要任何编码。这是正确的方式吗?我错过了什么吗?