Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
awsdocs
GitHub Repository: awsdocs/amazon-s3-developer-guide
Path: blob/master/code_examples/java_examples/S3Examples/HighLevelAbortMultipartUpload.java
4084 views
1
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
// SPDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-s3-developer-guide/blob/master/LICENSE-SAMPLECODE.)
3
4
import java.util.Date;
5
6
import com.amazonaws.AmazonServiceException;
7
import com.amazonaws.SdkClientException;
8
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
9
import com.amazonaws.services.s3.AmazonS3;
10
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
11
import com.amazonaws.services.s3.transfer.TransferManager;
12
import com.amazonaws.services.s3.transfer.TransferManagerBuilder;
13
14
public class HighLevelAbortMultipartUpload {
15
16
public static void main(String[] args) {
17
String clientRegion = "*** Client region ***";
18
String bucketName = "*** Bucket name ***";
19
20
try {
21
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
22
.withRegion(clientRegion)
23
.withCredentials(new ProfileCredentialsProvider())
24
.build();
25
TransferManager tm = TransferManagerBuilder.standard()
26
.withS3Client(s3Client)
27
.build();
28
29
// sevenDays is the duration of seven days in milliseconds.
30
long sevenDays = 1000 * 60 * 60 * 24 * 7;
31
Date oneWeekAgo = new Date(System.currentTimeMillis() - sevenDays);
32
tm.abortMultipartUploads(bucketName, oneWeekAgo);
33
}
34
catch(AmazonServiceException e) {
35
// The call was transmitted successfully, but Amazon S3 couldn't process
36
// it, so it returned an error response.
37
e.printStackTrace();
38
}
39
catch(SdkClientException e) {
40
// Amazon S3 couldn't be contacted for a response, or the client couldn't
41
// parse the response from Amazon S3.
42
e.printStackTrace();
43
}
44
}
45
}
46