Listing Versioned Objects in a Bucket
API Description
You can use this API to list versioned objects in a bucket. By default, a maximum of 1000 versioned objects are listed.
Method Definition
ObsClient.listVersions(bucketName, version)
Request Parameters
|
Field |
Type |
Optional or Mandatory |
Description |
|---|---|---|---|
|
bucketName |
str |
Mandatory |
Bucket name |
|
version |
Optional |
Request parameter for listing versioned objects in a bucket |
Returned Results
|
Type |
Description |
|---|---|
|
SDK common result object |
|
GetResult.body Type |
Description |
|---|---|
|
Response result of the request for listing versioned objects in a bucket |
Sample Code
try:
from obs 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())
Last Article: Listing Objects in a Bucket
Next Article: Obtaining Bucket Metadata
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.