Amazon web services 使用AWS S3静态web托管将文件上载到S3
我们一直在寻找将文件上传到S3的选项。我们正在考虑使用S3静态web托管的一个选项。在这个选项中,我们将有一个页面,我正在尝试编写一个带有上载选项的简单Index.html页面。我设置了以下桶策略:Amazon web services 使用AWS S3静态web托管将文件上载到S3,amazon-web-services,amazon-s3,Amazon Web Services,Amazon S3,我们一直在寻找将文件上传到S3的选项。我们正在考虑使用S3静态web托管的一个选项。在这个选项中,我们将有一个页面,我正在尝试编写一个带有上载选项的简单Index.html页面。我设置了以下桶策略: { "Version": "2012-10-17", "Statement": [ { "Sid": "Allow Public Access to All Objects", "Effect": "Allow",
{
"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>/*"
}
]
}
{
“版本”:“2012-10-17”,
“声明”:[
{
“Sid”:“允许公共访问所有对象”,
“效果”:“允许”,
“委托人”:“*”,
“行动”:[
“s3:GetObject”,
“s3:PutObject”
],
“资源”:“arn:aws:s3::/*”
}
]
}
以下是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>
*
得到
邮递
3000
授权
下面是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>
你好,世界
你好,世界
当我尝试使用webhosting 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
404未找到
代码:NoSuchKey
消息:指定的密钥不存在。
关键字:action_page.php
请求ID:
霍斯蒂德:
尝试检索自定义错误文档时出错
代码:NoSuchKey
消息:指定的密钥不存在。
关键字:error.html
如果我添加error.html页面,它将显示我的错误页面
现在我的想法是使用S3 webhosting将文件上传到bucket而不进行任何编码,这是正确的方法吗?我在这里遗漏了什么?您不能在S3静态网站上运行任何PHP文件-这需要后端服务器,并且您的表单正试图发布到“action_page.PHP” 那根本行不通 下面仅举一个示例说明如何继续: 在本例中,一个简单的HTML页面提供了一个基于浏览器的应用程序,用于在AmazonS3存储桶中创建相册,您可以将照片上载到其中。该应用程序允许您删除添加的照片和相册