@@ -0,0 +1,3709 @@
+package de.jeha.s3pt.tools;%0A%0Aimport com.amazonaws.ClientConfiguration;%0Aimport com.amazonaws.Protocol;%0Aimport com.amazonaws.auth.AWSCredentials;%0Aimport com.amazonaws.auth.BasicAWSCredentials;%0Aimport com.amazonaws.services.s3.AmazonS3;%0Aimport com.amazonaws.services.s3.AmazonS3Client;%0Aimport com.amazonaws.services.s3.S3ClientOptions;%0Aimport com.amazonaws.services.s3.model.*;%0Aimport de.jeha.s3pt.Constants;%0Aimport de.jeha.s3pt.utils.UserProperties;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Locale;%0Aimport java.util.Properties;%0A%0A/**%0A * @author jenshadlich@googlemail.com%0A */%0Apublic class MultiPartUpload %7B%0A%0A    private static final Logger LOG = LoggerFactory.getLogger(MultiPartUpload.class);%0A%0A    public static void main(String... args) throws IOException %7B%0A        Locale.setDefault(Locale.ENGLISH);%0A%0A        final Properties userProperties = UserProperties.fromHome().load(%22s3pt%22);%0A        final String accessKey = userProperties.getProperty(%22accessKey%22);%0A        final String secretKey = userProperties.getProperty(%22secretKey%22);%0A        final String endpoint = userProperties.getProperty(%22endpoint%22);%0A        final String bucket = %22testbucket%22;%0A        final String key = %22multipart_test.svg%22;%0A%0A        AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);%0A%0A        ClientConfiguration clientConfiguration = new ClientConfiguration()%0A                .withProtocol(Protocol.HTTP)%0A                .withUserAgent(%22MultiPartUpload%22)%0A                .withSignerOverride(Constants.S3_SIGNER_TYPE);%0A%0A        AmazonS3 s3Client = new AmazonS3Client(credentials, clientConfiguration);%0A        s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).disableChunkedEncoding().build());%0A        s3Client.setEndpoint(endpoint);%0A%0A        List%3CPartETag%3E partETags = new ArrayList%3C%3E();%0A%0A        InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(bucket, key);%0A        InitiateMultipartUploadResult initResponse = s3Client.initiateMultipartUpload(initRequest);%0A%0A        File file = new File(%22/User/jns/flamegraph.svg%22);%0A        long contentLength = file.length();%0A        long partSize = 32 * 1024;%0A%0A        try %7B%0A            // Step 2: Upload parts.%0A            long filePosition = 0;%0A            for (int i = 1; filePosition %3C contentLength; i++) %7B%0A                // Last part can be smaller. Adjust part size.%0A                partSize = Math.min(partSize, (contentLength - filePosition));%0A%0A                // Create request to upload a part.%0A                UploadPartRequest uploadRequest = new UploadPartRequest()%0A                        .withBucketName(bucket).withKey(key)%0A                        .withUploadId(initResponse.getUploadId()).withPartNumber(i)%0A                        .withFileOffset(filePosition)%0A                        .withFile(file)%0A                        .withPartSize(partSize);%0A%0A                // Upload part and add response to our list.%0A                partETags.add(s3Client.uploadPart(uploadRequest).getPartETag());%0A%0A                filePosition += partSize;%0A            %7D%0A%0A            // Step 3: Complete.%0A            CompleteMultipartUploadRequest compRequest = new%0A                    CompleteMultipartUploadRequest(bucket,%0A                    key,%0A                    initResponse.getUploadId(),%0A                    partETags);%0A%0A            s3Client.completeMultipartUpload(compRequest);%0A        %7D catch (Exception e) %7B%0A            s3Client.abortMultipartUpload(new AbortMultipartUploadRequest(%0A                    bucket, key, initResponse.getUploadId()));%0A        %7D%0A%0A    %7D%0A%0A%7D%0A

add multipart upload example