Amazon Simple Storage Service
Developer Guide (API Version 2006-03-01)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Abort Multipart Uploads

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 TransferManager class by providing your AWS credentials.

2

Execute the TransferManager.abortMultipartUploads method by passing the bucket name and a Date value.


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]Note

You can also abort a specific multipart upload. For more information, see Abort a Multipart Upload.