Listing Objects in a Bucket
API Description
You can use this API to list objects in a bucket. By default, a maximum of 1000 objects are listed.
Method Definition
ObsClient.listObjects(bucketName, prefix, marker, max_keys, delimiter)
Request Parameters
|
Field |
Type |
Optional or Mandatory |
Description |
|---|---|---|---|
|
bucketName |
str |
Mandatory |
Bucket name |
|
prefix |
str |
Optional |
Name prefix that the objects to be listed must contain |
|
marker |
str |
Optional |
Object name to start with when listing objects in a bucket. All objects are listed in the lexicographical order. |
|
max_keys |
int |
Optional |
Maximum number of objects returned in the response. The value ranges from 1 to 1000. If the value is not in this range, 1000 is returned by default. |
|
delimiter |
str |
Optional |
Character used to group object names. If the object name contains the delimiter parameter, the character string from the first character to the first delimiter in the object name is grouped under the single result element commonPrefix. (If a prefix is specified in the request, the prefix must be removed from the object name.) |
Returned Results
|
Type |
Description |
|---|---|
|
SDK common result object |
|
GetResult.body Type |
Description |
|---|---|
|
Response result of the request for listing objects |
Sample Code
try:
resp = obsClient.listObjects('bucketname', prefix='prefix', max_keys=100)
if resp.status < 300:
print('requestId:', resp.requestId)
print('name:', resp.body.name)
print('prefix:', resp.body.prefix)
print('max_keys:', resp.body.max_keys)
print('is_truncated:', resp.body.is_truncated)
index = 1
for content in resp.body.contents:
print('object [' + str(index) + ']')
print('key:', content.key)
print('lastModified:', content.lastModified)
print('etag:', content.etag)
print('size:', content.size)
print('storageClass:', content.storageClass)
print('owner_id:', content.owner.owner_id)
print('owner_name:', content.owner.owner_name)
index += 1
else:
print('errorCode:', resp.errorCode)
print('errorMessage:', resp.errorMessage)
except:
import traceback
print(traceback.format_exc())
Last Article: Deleting a Bucket
Next Article: Listing Versioned Objects in a Bucket
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.