Updated on 2024-09-05 GMT+08:00

Listing Multipart Uploads (SDK for Python)

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.

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.
  • To list ongoing multipart uploads in a bucket, you must have the ListBucketMultipartUploads permission.
  • 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(bucketName, multipart)

Request Parameters

Table 1 List of request parameters

Parameter

Type

Mandatory (Yes/No)

Description

bucket

str

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

multipart

ListMultipartUploadsRequest

No

Explanation:

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

encoding_type

str

No

Explanation:

Encoding type for Key in the response. If Key in the response contains control characters that are not supported by the XML 1.0 standard, you can specify this parameter to encode Key.

Value range:

url

Default value:

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

Table 2 ListMultipartUploadsRequest

Parameter

Type

Mandatory (Yes/No)

Description

prefix

str

No

Explanation:

Name prefix that the objects 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

max_uploads

int

or

str

No

Explanation:

Maximum number of listed multipart uploads

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

delimiter

str

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 CommonPrefix. If no prefix is specified, objects with the same string from the first character to the first delimiter are grouped into one CommonPrefix.

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 CommonPrefix with abcd as the prefix. If only delimiter is set to d, objects abcd and abcde are grouped into a CommonPrefix with abcd as the prefix, and bbcde is grouped separately into another CommonPrefix with bbcd as the prefix.

Value range:

The value must contain 1 to 1,024 characters.

Default value:

None

key_marker

str

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

upload_id_marker

str

No

Explanation:

Upload ID after which the multipart upload listing begins

Restrictions:

This parameter is valid only when used with key_marker. If both parameters are specified, 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

Responses

Table 3 List of returned results

Type

Description

GetResult

Explanation:

SDK common results

Table 4 GetResult

Parameter

Type

Description

status

int

Explanation:

HTTP status code

Value range:

A status code is a group of digits ranging from 2xx (indicating successes) to 4xx or 5xx (indicating errors). It indicates the status of a response. For more information, see Status Code.

Default value:

None

reason

str

Explanation:

Reason description.

Default value:

None

errorCode

str

Explanation:

Error code returned by the OBS server. If the value of status is less than 300, this parameter is left blank.

Default value:

None

errorMessage

str

Explanation:

Error message returned by the OBS server. If the value of status is less than 300, this parameter is left blank.

Default value:

None

requestId

str

Explanation:

Request ID returned by the OBS server

Default value:

None

indicator

str

Explanation:

Error indicator returned by the OBS server.

Default value:

None

hostId

str

Explanation:

Requested server ID. If the value of status is less than 300, this parameter is left blank.

Default value:

None

resource

str

Explanation:

Error source (a bucket or an object). If the value of status is less than 300, this parameter is left blank.

Default value:

None

header

list

Explanation:

Response header list, composed of tuples. Each tuple consists of two elements, respectively corresponding to the key and value of a response header.

Default value:

None

body

object

Explanation:

Result content returned after the operation is successful. If the value of status is larger than 300, this parameter is left blank. The value varies with the API being called. For details, see Bucket-Related APIs (SDK for Python) and Object-Related APIs (SDK for Python).

Default value:

None

Table 5 GetResult.body

GetResult.body Type

Description

ListMultipartUploadsResponse

Explanation:

Response to the request for listing multipart uploads

Table 6 ListMultipartUploadsResponse

Parameter

Type

Description

bucket

str

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

str

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

str

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

str

Explanation:

Object name to start with for the next multipart upload listing request. nextKeyMarker is returned when not all the objects are listed. You can set key_marker to this value in the next request to list the remaining multipart uploads.

Value range:

The value must contain 1 to 1,024 characters.

Default value:

None

nextUploadIdMarker

str

Explanation:

Upload ID to start with for the next multipart upload listing request. This parameter is used together with nextKeyMarker. nextUploadIdMarker is returned when not all the objects are listed. You can set upload_id_marker to this value in the next request to list the remaining multipart uploads.

Value range:

The value must contain 1 to 32 characters.

Default value:

None

maxUploads

int

Explanation:

Maximum number of listed multipart uploads, which is consistent with that 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

isTruncated

bool

Explanation:

Whether all results are returned in the response

Value range:

  • true: Not all results are returned.
  • false: All results are returned.

Default value:

None

prefix

str

Explanation:

Prefix that the object names in the multipart uploads to be listed must contain. This parameter 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

delimiter

str

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

upload

list of Upload

Explanation:

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

Default value:

None

commonPrefixs

list of CommonPrefix

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

encoding_type

str

Explanation:

Encoding type for key in the response. If key in the response contains control characters that are not supported by the XML 1.0 standard, you can specify this parameter to encode key.

Value range:

url

Default value:

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

Table 7 Upload

Parameter

Type

Description

key

str

Explanation:

Name of the object to be uploaded. 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

str

Explanation:

Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8

Value range:

The value must contain 1 to 32 characters.

Default value:

None

initiator

Initiator

Explanation:

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

Default value:

None

owner

Owner

Explanation:

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

Default value:

None

storageClass

str

Explanation:

Storage class of the object to be uploaded

Value range:

See Table 11.

Default value:

None

initiated

str

Explanation:

Time when the multipart upload is initiated

Restrictions:

The time must be in the ISO8601 format, for example, 2018-01-01T00:00:00.000Z.

Sample code: DateTime(year=2023, month=9, day=12)

Default value:

None

Table 8 CommonPrefix

Parameter

Type

Description

prefix

str

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 9 Initiator

Parameter

Type

Mandatory (Yes/No)

Description

id

str

Yes if used as a request parameter

Explanation:

Account (domain) ID of the initiator

Value range:

To obtain an account ID, see Obtaining the Account ID.

Default value:

None

name

str

No if used as a request parameter

Explanation:

Account name of the initiator

Restrictions:

The account name can contain 6 to 32 characters and must start with a letter. Only letters, digits, hyphens (-), and underscores (_) are allowed.

Default value:

None

Table 10 Owner

Parameter

Type

Mandatory (Yes/No)

Description

owner_id

str

Yes if used as a request parameter

Explanation:

Account (domain) ID of the owner

Value range:

To obtain the account ID, see How Do I Get My Account ID and IAM User ID? (SDK for Python)

Default value:

None

owner_name

str

No if used as a request parameter

Explanation:

Account name of the owner

Value range:

To obtain the account ID, see How Do I Get My Account ID and IAM User ID? (SDK for Python)

Default value:

None

Table 11 StorageClass

Parameter

Type

Description

STANDARD

Standard storage class

Explanation:

Features low access latency and high throughput and is used for storing massive, frequently accessed (multiple times a month) or small objects (< 1 MB) requiring quick response.

WARM

Infrequent Access storage class

Explanation:

Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but is instantly available when needed.

COLD

Archive storage class

Explanation:

Used for storing rarely accessed (once a year) data.

Code Examples

This example lists multipart uploads in a bucket.

 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
from obs import ObsClient
from obs import ListMultipartUploadsRequest
import os
import traceback

# Obtain an AK and SK pair using environment variables or import the AK and SK pair in other ways. Using hard coding may result in leakage.
# Obtain an AK and SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
ak = os.getenv("AccessKeyID")
sk = os.getenv("SecretAccessKey")
# (Optional) If you use a temporary AK and SK pair and a security token to access OBS, obtain them from environment variables.
security_token = os.getenv("SecurityToken")
# Set server to the endpoint corresponding to the bucket. Here uses CN-Hong Kong as an example. Replace it with the one in use.
server = "https://obs.ap-southeast-1.myhuaweicloud.com" 

# Create an obsClient instance.
# If you use a temporary AK and SK pair and a security token to access OBS, you must specify security_token when creating an instance.
obsClient = ObsClient(access_key_id=ak, secret_access_key=sk, server=server)
try:
    bucketName = "examplebucket"
    # Specify the prefix that the object names in the multipart uploads to be listed must contain.
    prefix = 'prefix'
    # Specify the maximum number (10 as an example) of returned multipart uploads. The value ranges from 1 to 1,000. If the value is not in this range, 1,000 is returned by default.
    max_uploads = 10
    # Specify request parameters for listing multipart uploads.
    multipart = ListMultipartUploadsRequest(prefix=prefix, max_uploads=max_uploads)
    # List multipart uploads in a bucket.
    resp = obsClient.listMultipartUploads(bucketName, multipart, encoding_type='url')

    # If status code 2xx is returned, the API is called successfully. Otherwise, the API call fails.
    if resp.status < 300:
        print('List Multipart Uploads Succeeded')
        print('requestId:', resp.requestId)
        print('bucket:', resp.body.bucket)
        print('prefix:', resp.body.prefix)
        print('maxUploads:', resp.body.maxUploads)
        print('isTruncated:', resp.body.isTruncated)
        index = 1
        for upload in resp.body.upload:
            print('upload [' + str(index) + ']')
            print('key:', upload.key)
            print('uploadId:', upload.uploadId)
            print('storageClass:', upload.storageClass)
            print('initiated:', upload.initiated)
            print('owner_id:', upload.owner.owner_id)
            print('owner_name:', upload.owner.owner_name)
            index += 1
    else:
        print('List Multipart Uploads Failed')
        print('requestId:', resp.requestId)
        print('errorCode:', resp.errorCode)
        print('errorMessage:', resp.errorMessage)
except:
    print('List Multipart Uploads Failed')
    print(traceback.format_exc())