You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
List objects
List unmerged objects (list multipart upload tasks) - Python SDK
Copy page
Download PDF
List unmerged objects (list multipart upload tasks) - Python SDK
This API is used to list multiversion objects in a bucket. This API returns a maximum of 1,000 multiversion objects in the bucket for each request. You can use request parameters to define the selection criteria for the objects to list.​
Notes​
To list multipart upload tasks, you need tos:ListBucketMultipartUploads permission on the bucket. For details, see IAM policy overview.​
Parameter description​
​
Parameter​
Description​
prefix​
Prefix for this query result.​
delimiter​
The character used to group object names.​
max_uploads​
Returns the maximum number of objects listed, default is 1000.​
Values: greater than 0 and less than or equal to 1000.​
key_marker​
Starting position for listing versioned objects. Objects are listed in alphabetical order after the specified start. Usually the next_marker value returned from the last request.​
​
Example code​
Simply list unmerged multipart upload tasks​
The following code lists up to 10 unmerged multipart upload tasks in the specified bucket bucket-test.​
​
import os​
import tos​
​
# Retrieve AKSK information from environment variables.​
ak = os.getenv('TOS_ACCESS_KEY')​
sk = os.getenv('TOS_SECRET_KEY')​
endpoint = "your endpoint"​
region = "your region"​
bucket_name = 'bucket-test'​
try:​
# Fill in "your endpoint" and "your region" with the corresponding Endpoint of the region where your Bucket is located. Taking the example of North China 2 (Beijing), fill in "your endpoint" with tos-cn-beijing.volces.com and "your region" with cn-beijing.​
client = tos.TosClientV2(ak, sk, endpoint, region)​
out = client.list_multipart_uploads(bucket_name, max_uploads=10)​
for upload in out.uploads:​
print('object key', upload.key)​
print('upload id', upload.upload_id)​
print('owner', upload.owner)​
print('storage class', upload.storage_class)​
except tos.exceptions.TosClientError as e:​
# Operation failed, catch client error, usually caused by invalid request parameters or network issues​
print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))​
except tos.exceptions.TosServerError as e:​
# Operation failed, catch server error, detailed error information can be obtained from the response​
print('fail with server error, code: {}'.format(e.code))​
# request id can be used to locate specific issues, it is strongly recommended to save it in the log.​
print('error with request id: {}'.format(e.request_id))​
print('error with message: {}'.format(e.message))​
print('error with http code: {}'.format(e.status_code))​
print('error with ec: {}'.format(e.ec))​
print('error with request url: {}'.format(e.request_url))​
except Exception as e:​
print('fail with unknown error: {}'.format(e))​
​
List all unmerged multipart upload tasks with the specified prefix​
The following code lists all unmerged multipart upload tasks under the prefix exampledir/ in bucket bucket-test.​
​
import os​
import tos​
​
# Retrieve AKSK information from environment variables.​
ak = os.getenv('TOS_ACCESS_KEY')​
sk = os.getenv('TOS_SECRET_KEY')​
endpoint = "your endpoint"​
region = "your region"​
bucket_name = 'bucket-test'​
prefix = 'exampledir/'​
try:​
# Fill in "your endpoint" and "your region" with the corresponding Endpoint of the region where your Bucket is located. Taking the example of North China 2 (Beijing), fill in "your endpoint" with tos-cn-beijing.volces.com and "your region" with cn-beijing.​
client = tos.TosClientV2(ak, sk, endpoint, region)​
is_truncated = True​
marker = ''​
while is_truncated:​
out = client.list_multipart_uploads(bucket_name, prefix=prefix, key_marker=marker)​
for upload in out.uploads:​
print('object key', upload.key)​
print('upload id', upload.upload_id)​
print('owner', upload.owner)​
print('storage class', upload.storage_class)​
is_truncated = out.is_truncated​
marker = out.next_key_marker​
except tos.exceptions.TosClientError as e:​
# Operation failed, catch client error, usually caused by invalid request parameters or network issues​
print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))​
except tos.exceptions.TosServerError as e:​
# Operation failed, catch server error, detailed error information can be obtained from the response​
print('fail with server error, code: {}'.format(e.code))​
# request id can be used to locate specific issues, it is strongly recommended to save it in the log.​
print('error with request id: {}'.format(e.request_id))​
print('error with message: {}'.format(e.message))​
print('error with http code: {}'.format(e.status_code))​
print('error with ec: {}'.format(e.ec))​
print('error with request url: {}'.format(e.request_url))​
except Exception as e:​
print('fail with unknown error: {}'.format(e))​
​
List all unmerged multipart upload tasks​
The following code lists all unmerged multipart upload tasks in bucket bucket-test.​
​
import os​
import tos​
​
# Retrieve AKSK information from environment variables.​
ak = os.getenv('TOS_ACCESS_KEY')​
sk = os.getenv('TOS_SECRET_KEY')​
endpoint = "your endpoint"​
region = "your region"​
bucket_name = 'bucket-test'​
try:​
# Fill in "your endpoint" and "your region" with the corresponding Endpoint of the region where your Bucket is located. Taking the example of North China 2 (Beijing), fill in "your endpoint" with tos-cn-beijing.volces.com and "your region" with cn-beijing.​
client = tos.TosClientV2(ak, sk, endpoint, region)​
is_truncated = True​
marker = ''​
while is_truncated:​
out = client.list_multipart_uploads(bucket_name, key_marker=marker)​
for upload in out.uploads:​
print('object key', upload.key)​
print('upload id', upload.upload_id)​
print('owner', upload.owner)​
print('storage class', upload.storage_class)​
is_truncated = out.is_truncated​
marker = out.next_key_marker​
except tos.exceptions.TosClientError as e:​
# Operation failed, catch client error, usually caused by invalid request parameters or network issues​
print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))​
except tos.exceptions.TosServerError as e:​
# Operation failed, catch server error, detailed error information can be obtained from the response​
print('fail with server error, code: {}'.format(e.code))​
# request id can be used to locate specific issues, it is strongly recommended to save it in the log.​
print('error with request id: {}'.format(e.request_id))​
print('error with message: {}'.format(e.message))​
print('error with http code: {}'.format(e.status_code))​
print('error with ec: {}'.format(e.ec))​
print('error with request url: {}'.format(e.request_url))​
except Exception as e:​
print('fail with unknown error: {}'.format(e))​
​
Recursively list unmerged multipart upload tasks by directory​
TOS only has the concept of objects. You can simulate directory functionality by creating an object that is 0 bytes and ends with a slash/.​
The directory function can be simulated using the parameters delimiter and prefix:​
  • First set delimiter to/Then set prefix to empty to return objects and subdirectory information in the root directory.​
  • Set delimiter to/Set the prefix as a subdirectory to return objects and subdirectories within that subdirectory.​
The following code lists unmerged multipart upload tasks in the bucket bucket-test by directory.​
​
import os​
import tos​
​
# Retrieve AKSK information from environment variables.​
ak = os.getenv('TOS_ACCESS_KEY')​
sk = os.getenv('TOS_SECRET_KEY')​
endpoint = "your endpoint"​
region = "your region"​
bucket_name = 'bucket-test'​
prefix = 'exampledir/'​
try:​
# Fill in "your endpoint" and "your region" with the corresponding Endpoint of the region where your Bucket is located. Taking the example of North China 2 (Beijing), fill in "your endpoint" with tos-cn-beijing.volces.com and "your region" with cn-beijing.​
client = tos.TosClientV2(ak, sk, endpoint, region)​
is_truncated = True​
marker = ''​
while is_truncated:​
out = client.list_multipart_uploads(bucket_name, key_marker=marker, delimiter='/', prefix=prefix)​
for prefix in out.common_prefixes:​
print('subDir', prefix)​
​
for upload in out.uploads:​
print('object key', upload.key)​
print('upload id', upload.upload_id)​
print('owner', upload.owner)​
print('storage class', upload.storage_class)​
is_truncated = out.is_truncated​
marker = out.next_key_marker​
except tos.exceptions.TosClientError as e:​
# Operation failed, catch client error, usually caused by invalid request parameters or network issues​
print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))​
except tos.exceptions.TosServerError as e:​
# Operation failed, catch server error, detailed error information can be obtained from the response​
print('fail with server error, code: {}'.format(e.code))​
# request id can be used to locate specific issues, it is strongly recommended to save it in the log.​
print('error with request id: {}'.format(e.request_id))​
print('error with message: {}'.format(e.message))​
print('error with http code: {}'.format(e.status_code))​
print('error with ec: {}'.format(e.ec))​
print('error with request url: {}'.format(e.request_url))​
except Exception as e:​
print('fail with unknown error: {}'.format(e))​
​
​
Last updated: 2025.09.17 18:22:11