I want to copy all the data from on bucket to another directory in another bucket on amazon s3 with java.
Like I have a bucket name sourceBucket and a destBucket and there is another directory in destBucket. i want to copy all the data from sourceBucket to that directory. And i am using java. I am unable to find the solution
Try :
ObjectListing objectListing = s3.listObjects(new ListObjectsRequest()
.withBucketName(bucketName)
.withPrefix(""));
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {s3client.copyObject(sourceBucketName, objectSummary.getKey(),
destinationBucketName, objectSummary.getKey());}
s3 doesn't have folders. The "structure" you see is a key. So just copy your objects with proper keys. From Programmer Guide: Code Samples:
S3Object[] filteredObjects = s3Service.listObjects("sourceBucket", "appData/", null);
for(S3Object object: filteredObjects ){
s3Service.copyObject("sourceBucket", "newAppData/" + object.getKey().substring(object.getKey().indexOf("/"), "destBucket", object, false);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With