• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Python SDK)
  4. Bucket-Related APIs
  5. GET Objects

GET Objects

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 Parameter

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 a single result element, commonPrefix. (If a prefix is specified in the request, the prefix must be removed from the object name.)

Returned Result

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

ListObjectsResponse

Response result of GET 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())