我有一个使用 nodeJs 的网站。在这里,用户可以上传他们的照片。我正在使用芥末来存储这些图片。我的问题是每次用户将图片发送到服务器时,它都会以私人状态保存。因为上传后用户看不到图片。我需要在存储桶上公开它,以便用户可以看到它。我的所有存储桶都可以免费阅读,但每次我上传文件时它都是私有的。如何让每张上传的图片都公开?
这些是我的上传参数
const paramsForUpload = {
Bucket: bucketName,
Key: filePath,
Body: file.data,
};
const options = {
partSize: 10 * 1024 * 1024, // 10 MB
queueSize: 10,
};
s3.upload(paramsForUpload,options, (err) =>{
....
})
我的政策
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucketname"
},
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucketname"
}
]
}
感谢您的帮助