| Did this page help you? Yes No Tell us about it... |
The TransferManager class provides a method,
abortMultipartUploads, to abort multipart uploads in
progress. An upload is considered to be in progress once you initiate it and until
you complete it or abort it. You provide a Date value and this
API aborts all the multipart uploads, on that bucket, that were initiated before the
specified Date and are still in progress.
Because you are billed for all storage associated with uploaded parts (see Multipart Upload and Pricing), it is important that you either complete the multipart upload to have the object created or abort the multipart upload to remove any uploaded parts.
The following tasks guide you through using the high-level Java classes to abort multipart uploads.
High-Level API Multipart Uploads Aborting Process
1 | Create an instance of the |
2 | Execute the |
The following Java code sample demonstrates the preceding tasks.
AWSCredentials myCredentials = new BasicAWSCredentials(myAccessKeyID, mySecretKey); TransferManager tm = new TransferManager(myCredentials); tm.abortMultipartUploads(existingBucketName, someDate);
Example
The following Java code aborts all multipart uploads in progress that were initiated on a specific bucket over a week ago. For instructions on how to create and test a working sample, see Testing the Java Code Examples
import java.util.Date;
import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.s3.transfer.TransferManager;
public class HighLevel_Java_AbortMultipartUploads {
public static void main(String[] args) throws Exception {
String existingBucketName = "*** Provide existing bucket name ***";
TransferManager tm = new TransferManager(new PropertiesCredentials(
HighLevel_Java_UploadFile.class.getResourceAsStream(
"AwsCredentials.properties")));
int sevenDays = 1000 * 60 * 60 * 24 * 7;
Date oneWeekAgo = new Date(System.currentTimeMillis() - sevenDays);
try {
tm.abortMultipartUploads(existingBucketName, oneWeekAgo);
} catch (AmazonClientException amazonClientException) {
System.out.println("Unable to upload file, upload was aborted.");
amazonClientException.printStackTrace();
}
}
}![]() | Note |
|---|---|
You can also abort a specific multipart upload. For more information, see Abort a Multipart Upload. |