Chris Lu
6 years ago
11 changed files with 193 additions and 99 deletions
-
63other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/HighLevelMultipartUpload.java
-
2other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/PutObject.java
-
6other/java/s3copy/copier/src/test/java/com/seaweedfs/s3/PutObjectTest.java
-
82weed/s3api/filer_multipart.go
-
4weed/s3api/filer_util.go
-
13weed/s3api/s3api_errors.go
-
54weed/s3api/s3api_object_handlers.go
-
44weed/s3api/s3api_object_multipart_handlers.go
-
10weed/s3api/s3api_server.go
-
3weed/server/filer_server_handlers_write.go
-
11weed/server/volume_server_handlers_write.go
@ -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(); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue