Listing Uploaded Parts (SDK for Python)
Function
This API lists the uploaded parts in a specified bucket. This request must contain the multipart upload ID.
You can list the uploaded parts of a specified multipart upload or of all ongoing multipart uploads. A maximum of 1,000 uploaded parts can be returned in a response. If your multipart upload has more than 1,000 parts, you need to send multiple requests to list all uploaded parts. Assembled parts will not be listed.
Restrictions
- To list uploaded parts, you must be the bucket owner or have the required permission (obs:object:ListMultipartUploadParts in IAM or ListMultipartUploadParts in a bucket policy). For details, see Introduction to OBS Access Control, IAM Custom Policies, and Configuring an Object Policy.
- A returned list can only be used for verification. After a multipart upload is complete, the result in the list is no longer valid. However, when part numbers and the ETag values returned by OBS are uploaded, the list of part numbers specified by the user will be reserved.
Method
ObsClient.listParts(bucketName, objectKey, uploadId, maxParts, partNumberMarker)
Request Parameters
Parameter |
Type |
Mandatory (Yes/No) |
Description |
---|---|---|---|
bucketName |
str |
Yes |
Explanation: Bucket name Restrictions:
Default value: None |
objectKey |
str |
Yes |
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.eu-west-101.myhuaweicloud.eu/folder/test.txt, the object name is folder/test.txt. Value range: The value must contain 1 to 1,024 characters. Default value: None
NOTE:
The object URL is in the following format: https://Bucket name.Domain name/Folder directory level/Object name. If this object is stored in the root directory of the bucket, its URL does not contain the folder directory level. |
uploadId |
str |
Yes |
Explanation: Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8 Value range: The value must contain 1 to 32 characters. Default value: None |
maxParts |
int |
No |
Explanation: Maximum number of uploaded parts that can be listed per page Restrictions: If the specified value is greater than 1000, only 1,000 parts are returned. Value range: The value ranges from 1 to 1000. Default value: 1000 |
partNumberMarker |
int |
No |
Explanation: Part number after which uploaded part listing begins Restrictions: OBS lists only parts with greater numbers than that specified by this parameter. Default value: None |
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 objectKey. |
Responses
Type |
Description |
---|---|
Explanation: SDK common results |
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 |
GetResult.body Type |
Description |
---|---|
Explanation: Response to the request for listing uploaded parts |
Parameter |
Type |
Description |
---|---|---|
bucketName |
str |
Explanation: Bucket name Restrictions:
Default value: None |
objectKey |
str |
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.eu-west-101.myhuaweicloud.eu/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 32 characters. Default value: None |
initiator |
Explanation: Initiator of the multipart upload. For details, see Table 7. Default value: None |
|
owner |
Explanation: Owner of the multipart upload, which is consistent with initiator. For details, see Table 8. Default value: None |
|
storageClass |
str |
Explanation: Object storage class Value range: See Table 6. Default value: None |
partNumberMarker |
int |
Explanation: Part number after which part listing begins, which is consistent with that set in the request Value range: An integer greater than or equal to 0 Default value: None |
nextPartNumberMarker |
int |
Explanation: Part number to start with for the next part listing request. nextPartNumberMarker is returned when not all the parts are listed. You can set partNumberMarker to this value in the next request to list the remaining parts. Value range: An integer greater than or equal to 0 Default value: None |
maxParts |
int |
Explanation: Maximum number of parts that can be listed per page. This parameter is consistent with that set in the request. Restrictions: If the specified value is greater than 1000, only 1,000 parts are returned. Value range: The value ranges from 1 to 1000. Default value: 1000 |
isTruncated |
bool |
Explanation: Whether all results are returned in the response Value range:
Default value: None |
parts |
list of Part |
Explanation: List of uploaded parts. For details, see Table 9. Default value: None |
encoding_type |
str |
Explanation: Encoding type for some elements in the response. If delimiter, key_marker, prefix, nextKeyMarker, and key contain control characters that are not supported by the XML 1.0 standard, you can set encoding_type to encode delimiter, key_marker, prefix (including the Prefix in commonPrefixes), nextKeyMarker, and key in the response. Value range: Value option: url Default value: None. If you leave this parameter blank, encoding is not applied to elements. |
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. |
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 |
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 |
Parameter |
Type |
Description |
---|---|---|
partNumber |
int |
Explanation: Part number Value range: An integer ranging from 1 to 10000 Default value: None |
lastModified |
str |
Explanation: Time when the part was last modified Default value: None |
etag |
str |
Explanation: Part ETag, which is a Base64-encoded, 128-bit MD5 value Value range: The value must contain 32 characters. Default value: None |
size |
int |
Explanation: Part size Default value: None |
Code Examples
This example lists the parts that have been uploaded in a multipart upload.
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 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/eu/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 EU-Dublin as an example. Replace it with the one in use. server = "https://obs.eu-west-101.myhuaweicloud.eu" # 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" objectKey = "objectname" # Specify the ID of the multipart upload. uploadId = "your uploadid" # Specify the maximum number (10 as an example) of parts that can be listed per page. maxParts = 10 # List the uploaded parts. resp = obsClient.listParts(bucketName, objectKey, uploadId, maxParts, 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 Parts Succeeded') print('requestId:', resp.requestId) print('bucketName:', resp.body.bucketName) print('objectKey:', resp.body.objectKey) print('uploadId:', resp.body.uploadId) print('storageClass:', resp.body.storageClass) print('isTruncated:', resp.body.isTruncated) print('initiator:', resp.body.initiator) print('owner:', resp.body.owner) index = 1 for part in resp.body.parts: print('part [' + str(index) + ']') print('partNumber:', part.partNumber) print('lastModified:', part.lastModified) print('etag:', part.etag) print('size:', part.size) index += 1 else: print('List Parts Failed') print('requestId:', resp.requestId) print('errorCode:', resp.errorCode) print('errorMessage:', resp.errorMessage) except: print('List Parts Failed') print(traceback.format_exc()) |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.