Giving read permission to object uploaded via PutObjectRequest in amazon s3
amazon-s3, amazon-web-services, java
Solution
You can create a bucket policy that make all resources (or those who match a wildcard) available.
Click on your bucket properties on aws S3 console and edit the bucket policy to something like :
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "auniqueid",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket/*"
}
]
}
Where `bucket` in the `Resource` parameter is your bucket name.
Also you can set public permission for a specific file via Java API :
PutObjectRequest por = new PutObjectRequest(bucketName, key, file);
por.setCannedAcl(CannedAccessControlList.PublicRead);
s3.putObject(por);
Problem
I am uploading text file to Amazon s3 bucket via java application. I want to set read access fot that file for everyone. Does anyone know how to do this ? or direct me to some appropriate resources ?