我正在遵循以下教程,以允许基于浏览器的上传到我的S3
存储桶。
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-photo-album.html
我完成了整个教程,但是当我从localhost
提交照片时,我得到403
的访问被拒绝,其中acl
设置为public-read
和400
acl
设置为public
。
我的IAM
政策如下所示
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"arn:aws:s3:::BUCKET_NAME/*"
]
}
]
}
我正在使用未经身份验证的匿名用户。
cognito
控制台正在显示unauthenticated
个用户,但我也不知道为什么。
我用来上传的功能如下
function uploadPDF() {
var file = $('#fileUpload').val();
var fileName = Date.now().toString() + ".pdf";
var albumPhotosKey = encodeURIComponent("files") + '/';
var photoKey = albumPhotosKey + fileName;
s3.upload({
Key: photoKey,
Body: file,
ACL: 'public'
}, function(err, data) {
if (err) {
console.log(err);
return alert('There was an error uploading your photo: ', err.message);
}
alert('Successfully uploaded photo.');
});
}
并且我已经按如下所示设置了AWS SDK
AWS.config.update({
region: 'ap-south-1',
credentials: new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'ap-south-1:IdentityPoolKey'
})
});
var s3 = new AWS.S3({
apiVersion: '2006-03-01',
params: {Bucket: albumBucketName}
});
基于this的答案,我尝试将IdentityPoolId
更改为us-east-1
,但未显示任何更改。