Uploading a file to a bucket
To upload a file to a bucket, we will first create a bucket, and then upload the object into the bucket. Along with uploading the object, we need to assign the access control list (ACL) so that a particular user group can access the object. Here we will set the ACL as
s3.putObject(new PutObjectRequest( bucketName, fileName, new File(filePath)) .withCannedAcl(CannedAccessControlList.PublicRead));
There are other canned access control lists, such as:
The complete code to upload a file to a bucket is as follows:
package com.chapter3; import java.io.File; import java.util.Date; import com.amazonaws.AmazonClientException; ...