diff options
Diffstat (limited to 'other/java')
| -rw-r--r-- | other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/HighLevelMultipartUpload.java | 63 | ||||
| -rw-r--r-- | other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/PutObject.java (renamed from other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/S3Copy.java) | 2 | ||||
| -rw-r--r-- | other/java/s3copy/copier/src/test/java/com/seaweedfs/s3/PutObjectTest.java (renamed from other/java/s3copy/copier/src/test/java/com/seaweedfs/s3/S3CopyTest.java) | 6 |
3 files changed, 67 insertions, 4 deletions
diff --git a/other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/HighLevelMultipartUpload.java b/other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/HighLevelMultipartUpload.java new file mode 100644 index 000000000..b86df95a0 --- /dev/null +++ b/other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/HighLevelMultipartUpload.java @@ -0,0 +1,63 @@ +package com.seaweedfs.s3; + +import com.amazonaws.AmazonServiceException; +import com.amazonaws.ClientConfiguration; +import com.amazonaws.SdkClientException; +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +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.transfer.TransferManager; +import com.amazonaws.services.s3.transfer.TransferManagerBuilder; +import com.amazonaws.services.s3.transfer.Upload; + +import java.io.File; + +public class HighLevelMultipartUpload { + + public static void main(String[] args) throws Exception { + String bucketName = "javabucket"; + String filePath = args[0]; + File file = new File(filePath); + String keyName = "path/to/" + file.getName(); + + try { + AWSCredentials credentials = new BasicAWSCredentials("ANY-ACCESSKEYID", "ANY-SECRETACCESSKEY"); + ClientConfiguration clientConfiguration = new ClientConfiguration(); + clientConfiguration.setSignerOverride("AWSS3V4SignerType"); + + AmazonS3 s3Client = AmazonS3ClientBuilder + .standard() + .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration( + "http://localhost:8333", Regions.US_WEST_1.name())) + .withPathStyleAccessEnabled(true) + .withClientConfiguration(clientConfiguration) + .withCredentials(new AWSStaticCredentialsProvider(credentials)) + .build(); + + TransferManager tm = TransferManagerBuilder.standard() + .withS3Client(s3Client) + .build(); + + // TransferManager processes all transfers asynchronously, + // so this call returns immediately. + Upload upload = tm.upload(bucketName, keyName, file); + System.out.println("Object upload started"); + + // Optionally, wait for the upload to finish before continuing. + upload.waitForCompletion(); + System.out.println("Object upload complete"); + } catch (AmazonServiceException e) { + // The call was transmitted successfully, but Amazon S3 couldn't process + // it, so it returned an error response. + e.printStackTrace(); + } catch (SdkClientException e) { + // Amazon S3 couldn't be contacted for a response, or the client + // couldn't parse the response from Amazon S3. + e.printStackTrace(); + } + } +} diff --git a/other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/S3Copy.java b/other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/PutObject.java index f00a0ad0a..021d01e34 100644 --- a/other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/S3Copy.java +++ b/other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/PutObject.java @@ -18,7 +18,7 @@ import java.io.File; /** * Hello world! */ -public class S3Copy { +public class PutObject { public static void main(String[] args) { AWSCredentials credentials = new BasicAWSCredentials("ANY-ACCESSKEYID", "ANY-SECRETACCESSKEY"); diff --git a/other/java/s3copy/copier/src/test/java/com/seaweedfs/s3/S3CopyTest.java b/other/java/s3copy/copier/src/test/java/com/seaweedfs/s3/PutObjectTest.java index 2bc89b87d..0404dab60 100644 --- a/other/java/s3copy/copier/src/test/java/com/seaweedfs/s3/S3CopyTest.java +++ b/other/java/s3copy/copier/src/test/java/com/seaweedfs/s3/PutObjectTest.java @@ -7,7 +7,7 @@ import junit.framework.TestSuite; /** * Unit test for simple App. */ -public class S3CopyTest +public class PutObjectTest extends TestCase { /** @@ -15,7 +15,7 @@ public class S3CopyTest * * @param testName name of the test case */ - public S3CopyTest(String testName ) + public PutObjectTest(String testName ) { super( testName ); } @@ -25,7 +25,7 @@ public class S3CopyTest */ public static Test suite() { - return new TestSuite( S3CopyTest.class ); + return new TestSuite( PutObjectTest.class ); } /** |
