1.注册用户
首先,去aws上注册一个免费的用户,我在这里遇到的问题是,电话验证失败,后来联系的人工客服给解决
2.Creating a Bucket
跳转到此地址:https://console.aws.amazon.com/s3/,创建一个新的bucket
3.管理身份池
到此地址https://console.aws.amazon.com/cognito,新建提个身份池
4.创建IAM
到此地址
https://console.aws.amazon.com/iam/home,选择角色
点击上一步创建的身份池对应的非验证角色,一般都是以身份池+Unautho_Role结尾的,
然后点击添加内联策略
选择json
拷贝一下的内容
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"arn:aws:s3:::BUCKET_NAME/*"
]
}
]
}
替换BUCKET_NAME
5.配置跨域
到S3的界面,https://console.aws.amazon.com/s3/,选择bucketname,点击进入,然后点击权限,选择CORS配置,
将以下信息拷贝
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
接下来就可以开始上传了
参考
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-photo-album.html