To set S3 objects public using the Android SDK you can attach a Bucket Policy to your bucket like:
{
"Version": "2012-10-17",
"Id": "Policy20160803001",
"Statement": [
{
"Sid": "Stmt20160803001",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::[BUCKET_NAME]/*"
}
]
}
With such policy, all objects in the given bucket will be public.
Or, if you don't want to make all objects public in the bucket, just the ones uploaded using your Android SDK, you can use:
AmazonS3 s3 = new AmazonS3Client(credentials);
s3.setObjectAcl(Constants.S3_BUCKET, key,CannedAccessControlList.PublicRead);
final TransferUtility transferUtility = new TransferUtility(s3, getActivity());
TransferObserver observer = transferUtility.upload(
Constants.S3_BUCKET, // S3 BUCKET TO UPLOAD FILE TO
key, // NAME OF THE FILE IN THE S3 BUCKET
file // FILE THAT WILL BE UPLOADED
);
Some related questions: