Updated on 2024-12-11 GMT+08:00

Listing Multipart Uploads (SDK for Java)

Function

This API lists ongoing multipart uploads.

Ongoing multipart uploads are the multipart uploads that have been initiated but have not been completed or aborted. A maximum of 1,000 multipart uploads can be returned in a response. If there are over 1,000 ongoing tasks satisfying the list criteria, you need to send more requests to query additional multipart uploads.

If you have any questions during development, post them on the Issues page of GitHub.

Restrictions

  • To list multipart uploads, you must be the bucket owner or have the required permission (obs:bucket:ListBucketMultipartUploads in IAM or ListBucketMultipartUploads in a bucket policy). For details, see Introduction to OBS Access Control, IAM Custom Policies, and Configuring an Object Policy.
  • The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.
  • By default, only the bucket owner and multipart upload initiator have this permission. The bucket owner can grant others the ListBucketMultipartUploads permission.

Method

obsClient.listMultipartUploads(ListMultipartUploadsRequest request)

Request Parameters

Table 1 List of request parameters

Parameter

Type

Mandatory (Yes/No)

Description

request

ListMultipartUploadsRequest

Yes

Explanation:

Request parameters for listing multipart uploads. For details, see Table 2.

Table 2 ListMultipartUploadsRequest

Parameter

Type

Mandatory (Yes/No)

Description

bucketName

String

Yes

Explanation:

Bucket name.

Restrictions:

  • A bucket name must be unique across all accounts and regions.
  • A bucket name:
    • Must be 3 to 63 characters long and start with a digit or letter. Lowercase letters, digits, hyphens (-), and periods (.) are allowed.
    • Cannot be formatted as an IP address.
    • Cannot start or end with a hyphen (-) or period (.).
    • Cannot contain two consecutive periods (..), for example, my..bucket.
    • Cannot contain periods (.) and hyphens (-) adjacent to each other, for example, my-.bucket or my.-bucket.
  • If you repeatedly create buckets of the same name in the same region, no error will be reported and the bucket attributes comply with those set in the first creation request.

Default value:

None

prefix

String

No

Explanation:

Prefix that the object names in the multipart uploads to be listed must contain.

Assume that you have the following objects: logs/day1, logs/day2, logs/day3, and ExampleObject.jpg. If you specify logs/ as the prefix, the multipart uploads of logs/day1, logs/day2, and logs/day3 will be returned. If you leave this parameter blank, all multipart uploads in the bucket will be returned.

Restrictions:

The value must contain 1 to 1,024 characters.

Default value:

None

delimiter

String

No

Explanation:

Object names are grouped by this parameter, which is often used with prefix. If a prefix is specified, objects with the same string from the prefix to the first delimiter are grouped into one commonPrefixes. If no prefix is specified, objects with the same string from the first character to the first delimiter are grouped into one commonPrefixes.

Assume that a bucket has objects abcd, abcde, and bbcde in it. If delimiter is set to d and prefix is set to a, objects abcd and abcde are grouped into a commonPrefixes with abcd as the prefix. If only delimiter is set to d, objects abcd and abcde are grouped into a commonPrefixes with abcd as the prefix, and bbcde is grouped separately into another commonPrefixes with bbcd as the prefix.

Value range:

The value must contain 1 to 1,024 characters.

Default value:

None

maxUploads

Integer

No

Explanation:

Maximum number of multipart uploads to list.

Restrictions:

If the specified value is greater than 1000, only 1,000 multipart uploads are returned.

Value range:

An integer from 1 to 1000

Default value:

1000

keyMarker

String

No

Explanation:

Object name after which the multipart upload listing begins.

Value range:

The value of nextKeyMarker in the response body of the last request.

Default value:

None

uploadIdMarker

String

No

Explanation:

Upload ID after which the multipart upload listing begins.

Restrictions:

This parameter must be used together with keyMarker, indicating multipart uploads with IDs greater than the specified uploadIdMarker for the specified keyMarker are listed.

Value range:

The value of nextUploadIdMarker in the response body of the last request.

Default value:

None

encodingType

String

No

Explanation:

Encoding type for some elements in the response. If delimiter, keyMarker, prefix, nextKeyMarker, and objectKey contain control characters that are not supported by the XML 1.0 standard, you can set encodingType to encode delimiter, keyMarker, prefix (including the prefix in commonPrefixes), nextKeyMarker, and objectKey in the response.

Value range:

url

Default value:

None. If you leave this parameter blank, encoding is not applied.

Responses

Table 3 MultipartUploadListing

Parameter

Type

Description

statusCode

int

Explanation:

HTTP status code.

Value range:

A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response.

For more information, see Status Code.

Default value:

None

responseHeaders

Map<String, Object>

Explanation:

HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header.

Default value:

None

bucket

String

Explanation:

Bucket name.

Restrictions:

  • A bucket name must be unique across all accounts and regions.
  • A bucket name:
    • Must be 3 to 63 characters long and start with a digit or letter. Lowercase letters, digits, hyphens (-), and periods (.) are allowed.
    • Cannot be formatted as an IP address.
    • Cannot start or end with a hyphen (-) or period (.).
    • Cannot contain two consecutive periods (..), for example, my..bucket.
    • Cannot contain periods (.) and hyphens (-) adjacent to each other, for example, my-.bucket or my.-bucket.
  • If you repeatedly create buckets of the same name in the same region, no error will be reported and the bucket attributes comply with those set in the first creation request.

Default value:

None

keyMarker

String

Explanation:

Object name after which the multipart upload listing begins, which is consistent with that set in the request.

Value range:

The value must contain 1 to 1,024 characters.

Default value:

None

uploadIdMarker

String

Explanation:

Upload ID after which the multipart upload listing begins, which is consistent with that set in the request.

Value range:

The value must contain 1 to 32 characters.

Default value:

None

nextKeyMarker

String

Explanation:

Object name to start with for the next multipart upload listing request. If only part of multipart uploads are returned for the current request, this parameter is included in the response for setting keyMarker in the subsequent request.

Value range:

The value must contain 1 to 1,024 characters.

Default value:

None

nextUploadIdMarker

String

Explanation:

Upload ID to start with for the next multipart upload listing request. It is used with the nextKeyMarker parameter. If only part of multipart uploads are returned for the current request, this parameter is included in the response for setting uploadIdMarker in the subsequent request.

Value range:

The value must contain 1 to 32 characters.

Default value:

None

prefix

String

Explanation:

Object name prefix in multipart uploads, which is consistent with that set in the request.

Assume that you have the following objects: logs/day1, logs/day2, logs/day3, and ExampleObject.jpg. If you specify logs/ as the prefix, the multipart uploads of logs/day1, logs/day2, and logs/day3 will be returned. If you leave this parameter blank, all multipart uploads in the bucket will be returned.

Restrictions:

The value must contain 1 to 1,024 characters.

Default value:

None

maxUploads

int

Explanation:

Maximum number of listed multipart uploads, which is consistent with that set in the request.

Restrictions:

If the specified value is greater than 1000, only 1,000 multipart uploads are returned.

Value range:

An integer from 1 to 1000

Default value:

1000

truncated

boolean

Explanation:

Whether all multipart uploads are returned in the response.

Value range:

  • true: Not all multipart uploads are returned.
  • false: All multipart uploads are returned.

Default value:

None

multipartTaskList

List<MultipartUpload>

Explanation:

List of multipart uploads. For details, see Table 4.

delimiter

String

Explanation:

A character used to group object names in multipart uploads, which is consistent with that set in the request. This parameter is often used with prefix. If a prefix is specified, objects with the same string from the prefix to the first delimiter are grouped into one commonPrefixes. If no prefix is specified, objects with the same string from the first character to the first delimiter are grouped into one commonPrefixes.

Assume that a bucket has objects abcd, abcde, and bbcde in it. If delimiter is set to d and prefix is set to a, objects abcd and abcde are grouped into a commonPrefixes with abcd as the prefix. If only delimiter is set to d, objects abcd and abcde are grouped into a commonPrefixes with abcd as the prefix, and bbcde is grouped separately into another commonPrefixes with bbcd as the prefix.

Value range:

The value must contain 1 to 1,024 characters.

Default value:

None

commonPrefixes

String[]

Explanation:

List of object name prefixes grouped according to the delimiter parameter (if specified).

Value range:

The value must contain 1 to 1,024 characters.

Default value:

None

Table 4 MultipartUpload

Parameter

Type

Description

bucketName

String

Explanation:

Bucket name.

Restrictions:

  • A bucket name must be unique across all accounts and regions.
  • A bucket name:
    • Must be 3 to 63 characters long and start with a digit or letter. Lowercase letters, digits, hyphens (-), and periods (.) are allowed.
    • Cannot be formatted as an IP address.
    • Cannot start or end with a hyphen (-) or period (.).
    • Cannot contain two consecutive periods (..), for example, my..bucket.
    • Cannot contain periods (.) and hyphens (-) adjacent to each other, for example, my-.bucket or my.-bucket.
  • If you repeatedly create buckets of the same name in the same region, no error will be reported and the bucket attributes comply with those set in the first creation request.

Default value:

None

objectKey

String

Explanation:

Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name.

For example, if the address for accessing the object is examplebucket.obs.ap-southeast-1.myhuaweicloud.com/folder/test.txt, the object name is folder/test.txt.

Value range:

The value must contain 1 to 1,024 characters.

Default value:

None

uploadId

String

Explanation:

Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8.

Value range:

The value must contain 1 to 32 characters.

Default value:

None

initiatedDate

java.util.Date

Explanation:

Time when the multipart upload is initiated.

Restrictions:

The time must be in the ISO8601 format.

Default value:

None

storageClass

StorageClassEnum

Explanation:

Storage class of the object to be uploaded.

Value range:

See Table 5.

Default value:

None

initiator

Owner

Explanation:

Initiator of the multipart upload. For details, see Table 6.

owner

Owner

Explanation:

Owner of the multipart upload, which is consistent with initiator. For details, see Table 6.

Table 5 StorageClassEnum

Constant

Default Value

Description

STANDARD

STANDARD

Standard storage class

WARM

WARM

Infrequent Access storage class.

COLD

COLD

Archive storage class.

Table 6 Owner

Parameter

Type

Mandatory (Yes/No)

Description

id

String

Yes

Explanation:

Account (domain) ID of the bucket owner.

Value range:

To obtain the account ID, see How Do I Get My Account ID and User ID?

Default value:

None

displayName

String

No

Explanation:

Account name of the owner.

Value range:

To obtain the account name, see How Do I Get My Account ID and User ID?

Default value:

None

Code Example: Listing Multipart Uploads

This example lists up to 1,000 multipart uploads of bucket examplebucket.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import com.obs.services.ObsClient;
import com.obs.services.exception.ObsException;
import com.obs.services.model.ListMultipartUploadsRequest;
import com.obs.services.model.MultipartUpload;
import com.obs.services.model.MultipartUploadListing;
public class ListMultipartUploads001 {
    public static void main(String[] args) {
        // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
        // Obtain an AK/SK pair on the management console.
        String ak = System.getenv("ACCESS_KEY_ID");
        String sk = System.getenv("SECRET_ACCESS_KEY_ID");
        // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage.
        // Obtain an AK/SK pair and a security token using environment variables or import them in other ways.
        String securityToken = System.getenv("SECURITY_TOKEN");
        // Enter the endpoint corresponding to the bucket. CN-Hong Kong is used here as an example. Replace it with the one in your actual situation.
        String endPoint = "https://obs.ap-southeast-1.myhuaweicloud.com";
        // Obtain an endpoint using environment variables or import it in other ways.
        //String endPoint = System.getenv("ENDPOINT");
        
        // Create an ObsClient instance.
        // Use the permanent AK/SK pair to initialize the client.
        ObsClient obsClient = new ObsClient(ak, sk,endPoint);
        // Use the temporary AK/SK pair and security token to initialize the client.
        // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint);

        try {
            ListMultipartUploadsRequest request = new ListMultipartUploadsRequest("examplebucket");
            MultipartUploadListing result = obsClient.listMultipartUploads(request);
            for (MultipartUpload upload : result.getMultipartTaskList()) {
                System.out.println("UploadId:" + upload.getUploadId());
                System.out.println("ObjectKey:" + upload.getObjectKey());
                System.out.println("InitiatedDate:" + upload.getInitiatedDate());
            }
            System.out.println("ListMultipartUploads successfully");
        } catch (ObsException e) {
            System.out.println("ListMultipartUploads failed");
            // Request failed. Print the HTTP status code.
            System.out.println("HTTP Code:" + e.getResponseCode());
            // Request failed. Print the server-side error code.
            System.out.println("Error Code:" + e.getErrorCode());
            // Request failed. Print the error details.
            System.out.println("Error Message:" + e.getErrorMessage());
            // Request failed. Print the request ID.
            System.out.println("Request ID:" + e.getErrorRequestId());
            System.out.println("Host ID:" + e.getErrorHostId());
            e.printStackTrace();
        } catch (Exception e) {
            System.out.println("ListMultipartUploads failed");
            // Print other error information.
            e.printStackTrace();
        }
    }
}

Code Example: Listing Multipart Uploads Using Pagination

This example lists over 1,000 multipart uploads using pagination.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import com.obs.services.ObsClient;
import com.obs.services.exception.ObsException;
import com.obs.services.model.ListMultipartUploadsRequest;
import com.obs.services.model.MultipartUpload;
import com.obs.services.model.MultipartUploadListing;
public class ListMultipartUploads002 {
    public static void main(String[] args) {
        // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
        // Obtain an AK/SK pair on the management console.
        String ak = System.getenv("ACCESS_KEY_ID");
        String sk = System.getenv("SECRET_ACCESS_KEY_ID");
        // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage.
        // Obtain an AK/SK pair and a security token using environment variables or import them in other ways.
        String securityToken = System.getenv("SECURITY_TOKEN");
        // Enter the endpoint corresponding to the bucket. CN-Hong Kong is used here as an example. Replace it with the one in your actual situation.
        String endPoint = "https://obs.ap-southeast-1.myhuaweicloud.com";
        // Obtain an endpoint using environment variables or import it in other ways.
        //String endPoint = System.getenv("ENDPOINT");
        
        // Create an ObsClient instance.
        // Use the permanent AK/SK pair to initialize the client.
        ObsClient obsClient = new ObsClient(ak, sk,endPoint);
        // Use the temporary AK/SK pair and security token to initialize the client.
        // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint);

        try {
            ListMultipartUploadsRequest request = new ListMultipartUploadsRequest("examplebucket");
            MultipartUploadListing result;
            do {
                result = obsClient.listMultipartUploads(request);
                for (MultipartUpload upload : result.getMultipartTaskList()) {
                    System.out.println("UploadId:" + upload.getUploadId());
                    System.out.println("ObjectKey:" + upload.getObjectKey());
                    System.out.println("InitiatedDate:" + upload.getInitiatedDate());
                }
                request.setKeyMarker(result.getNextKeyMarker());
                request.setUploadIdMarker(result.getNextUploadIdMarker());
            } while (result.isTruncated());
            System.out.println("ListMultipartUploads successfully");
        } catch (ObsException e) {
            System.out.println("ListMultipartUploads failed");
            // Request failed. Print the HTTP status code.
            System.out.println("HTTP Code:" + e.getResponseCode());
            // Request failed. Print the server-side error code.
            System.out.println("Error Code:" + e.getErrorCode());
            // Request failed. Print the error details.
            System.out.println("Error Message:" + e.getErrorMessage());
            // Request failed. Print the request ID.
            System.out.println("Request ID:" + e.getErrorRequestId());
            System.out.println("Host ID:" + e.getErrorHostId());
            e.printStackTrace();
        } catch (Exception e) {
            System.out.println("ListMultipartUploads failed");
            // Print other error information.
            e.printStackTrace();
        }
    }
}