Search in sources :

Example 21 with MultipartUpload

use of software.amazon.awssdk.services.s3.model.MultipartUpload in project aws-doc-sdk-examples by awsdocs.

the class LowLevelAbortMultipartUpload method main.

public static void main(String[] args) {
    Regions clientRegion = Regions.DEFAULT_REGION;
    String bucketName = "*** Bucket name ***";
    try {
        AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(clientRegion).withCredentials(new ProfileCredentialsProvider()).build();
        // Find all in-progress multipart uploads.
        ListMultipartUploadsRequest allMultipartUploadsRequest = new ListMultipartUploadsRequest(bucketName);
        MultipartUploadListing multipartUploadListing = s3Client.listMultipartUploads(allMultipartUploadsRequest);
        List<MultipartUpload> uploads = multipartUploadListing.getMultipartUploads();
        System.out.println("Before deletions, " + uploads.size() + " multipart uploads in progress.");
        // Abort each upload.
        for (MultipartUpload u : uploads) {
            System.out.println("Upload in progress: Key = \"" + u.getKey() + "\", id = " + u.getUploadId());
            s3Client.abortMultipartUpload(new AbortMultipartUploadRequest(bucketName, u.getKey(), u.getUploadId()));
            System.out.println("Upload deleted: Key = \"" + u.getKey() + "\", id = " + u.getUploadId());
        }
        // Verify that all in-progress multipart uploads have been aborted.
        multipartUploadListing = s3Client.listMultipartUploads(allMultipartUploadsRequest);
        uploads = multipartUploadListing.getMultipartUploads();
        System.out.println("After aborting uploads, " + uploads.size() + " multipart uploads in progress.");
    } 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();
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) SdkClientException(com.amazonaws.SdkClientException) AmazonServiceException(com.amazonaws.AmazonServiceException) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) MultipartUploadListing(com.amazonaws.services.s3.model.MultipartUploadListing) Regions(com.amazonaws.regions.Regions) AbortMultipartUploadRequest(com.amazonaws.services.s3.model.AbortMultipartUploadRequest) MultipartUpload(com.amazonaws.services.s3.model.MultipartUpload) ListMultipartUploadsRequest(com.amazonaws.services.s3.model.ListMultipartUploadsRequest)

Example 22 with MultipartUpload

use of software.amazon.awssdk.services.s3.model.MultipartUpload in project beam by apache.

the class S3WritableByteChannel method close.

@Override
public void close() throws IOException {
    open = false;
    if (uploadBuffer.remaining() > 0) {
        flush();
    }
    CompletedMultipartUpload completedMultipartUpload = CompletedMultipartUpload.builder().parts(completedParts).build();
    CompleteMultipartUploadRequest request = CompleteMultipartUploadRequest.builder().bucket(path.getBucket()).key(path.getKey()).uploadId(uploadId).multipartUpload(completedMultipartUpload).build();
    try {
        s3Client.completeMultipartUpload(request);
    } catch (SdkClientException e) {
        throw new IOException(e);
    }
}
Also used : SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) IOException(java.io.IOException) CompletedMultipartUpload(software.amazon.awssdk.services.s3.model.CompletedMultipartUpload) CompleteMultipartUploadRequest(software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest)

Aggregations

MultipartUpload (com.amazonaws.services.s3.model.MultipartUpload)13 MultipartUploadListing (com.amazonaws.services.s3.model.MultipartUploadListing)12 ArrayList (java.util.ArrayList)9 ListMultipartUploadsRequest (com.amazonaws.services.s3.model.ListMultipartUploadsRequest)7 Test (org.junit.Test)6 CompleteMultipartUploadRequest (software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest)5 CompletedMultipartUpload (software.amazon.awssdk.services.s3.model.CompletedMultipartUpload)5 CompletedPart (software.amazon.awssdk.services.s3.model.CompletedPart)5 AmazonClientException (com.amazonaws.AmazonClientException)4 AmazonServiceException (com.amazonaws.AmazonServiceException)4 IOException (java.io.IOException)4 TestRunner (org.apache.nifi.util.TestRunner)4 CreateMultipartUploadRequest (software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest)4 CreateMultipartUploadResponse (software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse)4 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)4 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)3 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)3 InputStream (java.io.InputStream)3 Date (java.util.Date)3 Ignore (org.junit.Ignore)3