How to do copy object using s3-transfer-manager?

553 views Asked by At

I am working on java project where I am using s3 services so I am using aws-sdk version 2.17 and transfer manager 2.17 to perform operation like copy, upload, download. My issue is that I want to show progress of copy process so I am using copy api of transfer manager but it was not working . Here are code snippet.

  public static void test(){
    try {
        String sAccessKey="XXXXX";
        String sSecretKey="XXXXXX";
        AwsBasicCredentials awsCreds = AwsBasicCredentials.create(
                sAccessKey,
                sSecretKey);
        AwsCredentialsProvider awsCredentialsProvider =  StaticCredentialsProvider.create(awsCreds);
        S3TransferManager s3TransferManager = S3TransferManager
                .builder()
                .s3ClientConfiguration(S3ClientConfiguration.builder()
                        .region(Region.EU_WEST_1)
                        .credentialsProvider(awsCredentialsProvider).build())
                .build();
      
        Copy copy = s3TransferManager.copy(c -> c
                        .copyObjectRequest(r -> r
                                .sourceBucket("source_bucket")
                                .sourceKey("test.json")
                                .destinationBucket("destination_bucket")
                                .destinationKey("test.json"))
                 .overrideConfiguration(o -> o.addListener( LoggingTransferListener.create()))
        );
        CompletedCopy completedCopy = copy.completionFuture().join();
        System.out.println(copy.progress().snapshot().transferSizeInBytes());
        System.out.println(copy.progress().snapshot().bytesTransferred());

    } catch (S3Exception e) {
        throw e;
    }
}

When I executes above mention code then I am getting error is:-

software.amazon.awssdk.services.s3.model.S3Exception: null (Service: S3, Status Code: 301, Request ID: 6Y67D05YMB2VPCTZ, Extended Request ID: djU25dflTcZ0NExxqZQDXQ9SSwcQaMvvMAGrcfRDbDhvzgaws3twq1arytQ/Qd14kXNDpWYdbgA=)

Please suggest.

1

There are 1 answers

5
Hai Mai On