简体   繁体   中英

How to move/copy list of S3 Objects from one folder to folder in java?

I want to copy/move a list of S3 objects (all the S3 objects in a given folder) from one folder to another in the same bucket. I could write the code for on object as follows.

public static S3Response copySingleFile(S3Request s3Request) {
        S3Validation.validateCopyMoveArgs(s3Request);
        CopyObjectRequest copyObjectRequest=new CopyObjectRequest(s3Request.getBucketName(), s3Request.getSourcekey(), s3Request.getBucketName(), s3Request.getDestKey());
        AWSClient.getS3Client().copyObject(copyObjectRequest);
        return response;
    }

I think it should be done by making a list of object of that given folder and copy the list to the destination. I hope the logic is that but I'm in trouble in coding part.

The copyObject() API call to Amazon S3 only allows one object to be copied. You will need to iterate through the list of objects and copy each object individually.

You will need a listObjectsV2() call to obtain the list of existing objects, then call copyObject() for each of them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM