Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Use ListMultipartUploads
with an Amazon SDK or CLI
The following code examples show how to use ListMultipartUploads
.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in
context in the following code example:
- CLI
-
- Amazon CLI
-
The following command lists all of the active multipart uploads for a bucket named amzn-s3-demo-bucket
:
aws s3api list-multipart-uploads --bucket amzn-s3-demo-bucket
Output:
{
"Uploads": [
{
"Initiator": {
"DisplayName": "username",
"ID": "arn:aws:iam::0123456789012:user/username"
},
"Initiated": "2015-06-02T18:01:30.000Z",
"UploadId": "dfRtDYU0WWCCcH43C3WFbkRONycyCpTJJvxu2i5GYkZljF.Yxwh6XG7WfS2vC4to6HiV6Yjlx.cph0gtNBtJ8P3URCSbB7rjxI5iEwVDmgaXZOGgkk5nVTW16HOQ5l0R",
"StorageClass": "STANDARD",
"Key": "multipart/01",
"Owner": {
"DisplayName": "aws-account-name",
"ID": "100719349fc3b6dcd7c820a124bf7aecd408092c3d7b51b38494939801fc248b"
}
}
],
"CommonPrefixes": []
}
In progress multipart uploads incur storage costs in Amazon S3. Complete or abort an active multipart upload to remove its parts from your account.
- Java
-
- SDK for Java 2.x
-
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.ListMultipartUploadsRequest;
import software.amazon.awssdk.services.s3.model.ListMultipartUploadsResponse;
import software.amazon.awssdk.services.s3.model.MultipartUpload;
import software.amazon.awssdk.services.s3.model.S3Exception;
import java.util.List;
/**
* Before running this Java V2 code example, set up your development
* environment, including your credentials.
*
* For more information, see the following documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
*/
public class ListMultipartUploads {
public static void main(String[] args) {
final String usage = """
Usage:
<bucketName>\s
Where:
bucketName - The name of the Amazon S3 bucket where an in-progress multipart upload is occurring.
""";
if (args.length != 1) {
System.out.println(usage);
System.exit(1);
}
String bucketName = args[0];
Region region = Region.US_EAST_1;
S3Client s3 = S3Client.builder()
.region(region)
.build();
listUploads(s3, bucketName);
s3.close();
}
/**
* Lists the multipart uploads currently in progress in the specified Amazon S3 bucket.
*
* @param s3 the S3Client object used to interact with Amazon S3
* @param bucketName the name of the Amazon S3 bucket to list the multipart uploads for
*/
public static void listUploads(S3Client s3, String bucketName) {
try {
ListMultipartUploadsRequest listMultipartUploadsRequest = ListMultipartUploadsRequest.builder()
.bucket(bucketName)
.build();
ListMultipartUploadsResponse response = s3.listMultipartUploads(listMultipartUploadsRequest);
List<MultipartUpload> uploads = response.uploads();
for (MultipartUpload upload : uploads) {
System.out.println("Upload in progress: Key = \"" + upload.key() + "\", id = " + upload.uploadId());
}
} catch (S3Exception e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
}
For a complete list of Amazon SDK developer guides and code examples, see
Developing with Amazon S3 using the Amazon SDKs.
This topic also includes information about getting started and details about previous SDK versions.