• Object Storage Service

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

GET Object versions

API Description

You can use this API to list versioning objects in a bucket. By default, a maximum of 1000 versioning objects are listed.

Method Definition

ObsClient.listVersions(bucketName, version)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

version

Versions

Optional

Request parameter of GET Object versions

Returned Result

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

ObjectVersions

Response result of GET Object versions

Sample Code

try:
    from com.obs.models.versions import Versions 
     
    resp = obsClient.listVersions('bucketname', version=Versions(prefix='prefix',max_keys=100)) 
     
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
        print('name:', resp.body.head.name) 
        print('prefix:', resp.body.head.prefix) 
        print('maxKeys:', resp.body.head.maxKeys) 
        print('isTruncated:', resp.body.head.isTruncated) 
        index = 1 
        for version in resp.body.versions: 
            print('version [' + str(index) + ']') 
            print('key:', version.key) 
            print('versionId:', version.versionId) 
            print('lastModified:', version.lastModified) 
            print('etag:', version.etag) 
            print('size:', version.size) 
            print('storageClass:', version.storageClass) 
            print('owner_id:', version.owner.owner_id) 
            print('owner_name:', version.owner.owner_name) 
            index += 1 
         
        index = 1 
        for marker in resp.body.markers: 
            print('marker [' + str(index) + ']') 
            print('key:', marker.key) 
            print('versionId:', marker.versionId) 
            print('lastModified:', marker.lastModified) 
            print('owner_id:', marker.owner.owner_id) 
            print('owner_name:', marker.owner.owner_name) 
            index += 1 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())