Amazon Simple Storage Service
Developer Guide (API Version 2006-03-01)

Abort Multipart Uploads

The following example uses the high-level Java API (the TransferManager class) to abort all in-progress multipart uploads that were initiated on a specific bucket over a week ago. For instructions on creating and testing a working sample, see Testing the Amazon S3 Java Code Examples.

import java.util.Date; import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import; import; import; import; public class HighLevelAbortMultipartUpload { public static void main(String[] args) { String clientRegion = "*** Client region ***"; String bucketName = "*** Bucket name ***"; try { AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withRegion(clientRegion) .withCredentials(new ProfileCredentialsProvider()) .build(); TransferManager tm = TransferManagerBuilder.standard() .withS3Client(s3Client) .build(); // sevenDays is the duration of seven days in milliseconds. long sevenDays = 1000 * 60 * 60 * 24 * 7; Date oneWeekAgo = new Date(System.currentTimeMillis() - sevenDays); tm.abortMultipartUploads(bucketName, oneWeekAgo); } 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(); } } }