Listing Uploaded Parts¶
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).
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, extensionHeaders)
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. 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 |
extensionHeaders | dict | No | Explanation: Extension headers. Value range: See User-defined Headers. Default value: None |
Responses¶
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. 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, the value of body is null. The value varies with the API being called. For details, see Bucket-Related APIs and Object-Related APIs. 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. 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 |
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 | Warm 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 | Cold 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: 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? 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? 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.
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.
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 of the region where the bucket is located.
server = "https://your-endpoint"
# 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())