Home » Android » amazon web services – How to get the progress of copy operation in AWS copy operation in android?

amazon web services – How to get the progress of copy operation in AWS copy operation in android?

Posted by: admin February 24, 2020 Leave a comment

Questions:

I try to copy one file from one folder to other folder inside the same bucket. For copying the file i use CopyObjectRequest class. But i do not know how can i get the progress of copy operation?
So please help me in it , how can i get the progress status of copy operation.

For copy operation i followed this way-

try {
        AmazonS3 s3Client =new AmazonS3Client(credentials,cc);

        // Copy the object into a new object in the same bucket.
        CopyObjectRequest copyObjRequest = new CopyObjectRequest(bucketName, sourceKey, "wedorias-new", "test/test111/logo.png"/*destinationKey*/);
        s3Client.copyObject(copyObjRequest);

        if (copyObjRequest.isRequesterPays()){

            System.out.println("sadfbgnh==");
        }

    } catch (AmazonServiceException e) {
        // The call was transmitted successfully, but Amazon S3 couldn't process
        // it, so it returned an error response.
        e.printStackTrace();
        System.out.println("exception==!"+e.getErrorMessage());
        System.out.println("exception==!"+e.getErrorCode());
        System.out.println("exception==!"+e.getMessage());
    } catch (Exception e) {

        e.printStackTrace();
        System.out.println("exception==!"+e.getMessage());
    }
How to&Answers:

If you want to copy one object from one folder to another one (Or other Buckets if it’s the case) and check the progress, you will have to use Amazon S3 Multipart Upload.

AWS docs have a nice example called Copy an Object Using the AWS SDK for Java Multipart Upload API, it shows you what you have to do to set it up and check the progress of the copy.

// Get the object size to track the end of the copy operation. 
GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest(sourceBucketName, sourceObjectKey); 
ObjectMetadata metadataResult = s3Client.getObjectMetadata(metadataRequest); 
long objectSize = metadataResult.getContentLength();

Notice

  • Multipart upload is a must when the object is greater than 5GB.

  • Multipart upload is recommended when the object is greater than 100MB.

  • Multipart upload doesn’t work if the object is less than 5MB.