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();
}
}
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);
}
}
Aggregations