From a9aa2d581fcb246d01bad603cd1164d992ad2cfc Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 16 Feb 2023 21:30:55 -0800 Subject: [PATCH] add some more example --- other/java/s3copier/pom.xml | 4 ++++ .../seaweedfs/s3/HighLevelMultipartUpload.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/other/java/s3copier/pom.xml b/other/java/s3copier/pom.xml index c3ff30932..0050c70da 100644 --- a/other/java/s3copier/pom.xml +++ b/other/java/s3copier/pom.xml @@ -5,6 +5,10 @@ copier jar 1.0-SNAPSHOT + + 18 + 18 + copier http://maven.apache.org diff --git a/other/java/s3copier/src/main/java/com/seaweedfs/s3/HighLevelMultipartUpload.java b/other/java/s3copier/src/main/java/com/seaweedfs/s3/HighLevelMultipartUpload.java index b86df95a0..06e623886 100644 --- a/other/java/s3copier/src/main/java/com/seaweedfs/s3/HighLevelMultipartUpload.java +++ b/other/java/s3copier/src/main/java/com/seaweedfs/s3/HighLevelMultipartUpload.java @@ -10,6 +10,8 @@ import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.regions.Regions; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import com.amazonaws.services.s3.model.CreateBucketRequest; +import com.amazonaws.services.s3.model.GetBucketLocationRequest; import com.amazonaws.services.s3.transfer.TransferManager; import com.amazonaws.services.s3.transfer.TransferManagerBuilder; import com.amazonaws.services.s3.transfer.Upload; @@ -42,6 +44,19 @@ public class HighLevelMultipartUpload { .withS3Client(s3Client) .build(); + + if (!s3Client.doesBucketExistV2(bucketName)) { + // Because the CreateBucketRequest object doesn't specify a region, the + // bucket is created in the region specified in the client. + s3Client.createBucket(new CreateBucketRequest(bucketName)); + + // Verify that the bucket was created by retrieving it and checking its location. + String bucketLocation = s3Client.getBucketLocation(new GetBucketLocationRequest(bucketName)); + System.out.println("Bucket location: " + bucketLocation); + } else { + System.out.println("Bucket already exists"); + } + // TransferManager processes all transfers asynchronously, // so this call returns immediately. Upload upload = tm.upload(bucketName, keyName, file);