I have a structure on amazon like this -
(bucket name) MyImages
--- (key) general
---- 1.jpg
---- 2.jpg
I have created the key (general) by using S3 Firefox Organizer tool and set read permission for all. Now, by a java program when I am uploading the images inside this key, I want to set the permission of each object as the key have. But its not happening and I have to write some extra line of code for setting up the permissions of each object.
AccessControlList acl = s3.getBucketAcl("MyImages");
// give everyone read access
acl.grantPermission(GroupGrantee.AllUsers, Permission.Read);
s3.setObjectAcl("MyImages", "general/1.jpg", acl);
Is there any way to get rid of above code. Why the objects are not getting the permission as the key or bucket?
The following code works for me. Replace file_to_save with the file object you are writing to S3.
PutObjectRequest por = new PutObjectRequest("MyImages", "general/1.jpg", file_to_save);
o.setCannedAcl(CannedAccessControlList.PublicRead);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With