Browse Source

add some more example

pull/4217/head
chrislu 2 years ago
parent
commit
a9aa2d581f
  1. 4
      other/java/s3copier/pom.xml
  2. 15
      other/java/s3copier/src/main/java/com/seaweedfs/s3/HighLevelMultipartUpload.java

4
other/java/s3copier/pom.xml

@ -5,6 +5,10 @@
<artifactId>copier</artifactId> <artifactId>copier</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
</properties>
<name>copier</name> <name>copier</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>

15
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.regions.Regions;
import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder; 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.TransferManager;
import com.amazonaws.services.s3.transfer.TransferManagerBuilder; import com.amazonaws.services.s3.transfer.TransferManagerBuilder;
import com.amazonaws.services.s3.transfer.Upload; import com.amazonaws.services.s3.transfer.Upload;
@ -42,6 +44,19 @@ public class HighLevelMultipartUpload {
.withS3Client(s3Client) .withS3Client(s3Client)
.build(); .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, // TransferManager processes all transfers asynchronously,
// so this call returns immediately. // so this call returns immediately.
Upload upload = tm.upload(bucketName, keyName, file); Upload upload = tm.upload(bucketName, keyName, file);

Loading…
Cancel
Save