Reputation: 1019
I have a website working with nodeJs. In here users can upload their pictures. I'm using Wasabi to store that pictures. My problem is everytime a user send a picture to server it will save it with private condition. Because of that after uploading users can't see the picture. I need to make it public on the bucket so users can see it. My all buckets are free to read but everytime I upload a file it will be private. How can I make every uploaded picture public?
these are my upload params
const paramsForUpload = {
Bucket: bucketName,
Key: filePath,
Body: file.data,
};
const options = {
partSize: 10 * 1024 * 1024, // 10 MB
queueSize: 10,
};
s3.upload(paramsForUpload,options, (err) =>{
....
})
My policy
{
"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"
}
]
}
Thanks for helping
Upvotes: 2
Views: 2782
Reputation: 270074
The bucket policy should refer to the contents of the bucket, with a trailing /*
:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucketname/*"
}
]
}
Upvotes: 1
Reputation: 1019
You can make public upload with adding
ACL: 'public-read',
to your upload params like
const paramsForUpload = {
Bucket: bucketName,
Key: filePath,
Body: file.data,
ACL: 'public-read',
};
Upvotes: 3