How to mark a certain S3 file as Make Public

amazon-s3, amazon-web-services, java

Solution

Use method `setCannedAcl(CannedAccessControlList.PublicRead)` to change Access control rights. Read java doc for details here

Sample Code:

BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(ACCESS_KEY,SECRET_KEY);   
AmazonS3 s3 = new AmazonS3Client(basicAWSCredentials);

PutObjectRequest putObj = new PutObjectRequest(bucketName, objectKey, fileToUpload);

// making the object Public
putObj.setCannedAcl(CannedAccessControlList.PublicRead);

s3.putObject(putObj);

Problem

How to mark a certain S3 file as Make Public via the webservices API.

Original source