Copying objects
Amazon S3 SDK provides a copy object functionality that allows you to copy Amazon S3 objects from one bucket to another. For this, you have to define the source bucket name, source object key, destination bucket name, and the destination object key. The following is the API that we can use to copy the object:
public void copyObjects1(String sourceBucketName, String sourceObjectKey, String destinationBucketName, String destinationObjectKey){ System.out.println("================ COPY OBJECT ================ "); try { s3.copyObject(sourceBucketName, sourceObjectKey, destinationBucketName, destinationObjectKey); } catch (AmazonServiceException exception) { exception.printStackTrace(); } catch (AmazonClientException exception) { exception.printStackTrace(); } }
We can also copy objects using the CopyObjectRequest
class. This is used when we want to add the metadata of a newly copied object along with CannedAccessControlList
and...