【发布时间】:2017-05-04 21:57:54
【问题描述】:
我们一直在研究将文件上传到 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>
当我尝试使用虚拟主机 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 虚拟主机将文件上传到存储桶而不进行任何编码是正确的方法吗?我在这里错过了什么?
【问题讨论】:
标签: amazon-web-services amazon-s3