• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Node.js 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(parameter, callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

String

Mandatory

Bucket name

Prefix

String

Optional

Prefix that the object names to be listed must contain

KeyMarker

String

Optional

Object name to start with when listing versioning objects in a bucket. All objects following this parameter are listed in the lexicographical order of object names.

MaxKeys

Number

Optional

Maximum number of versioning objects returned. The value ranges from 1 to 1000. If the value is not in this range, 1000 is returned by default.

Delimiter

String

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 parameter 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.)

VersionIdMarker

String

Optional

Object name to start with when listing versioning objects in a bucket. All versioning objects are listed in the lexicographical order by object name and version ID. This parameter must be used together with KeyMarker.

If the value of VersionIdMarker is not a version ID specified by KeyMarker, VersionIdMarker does not take effect.

Returned Result (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

Location

String

Bucket location

Bucket

String

Bucket name

Delimiter

String

Character used to group object names, which is consistent with that set in the request

Prefix

String

Object name prefix, which is consistent with that set in the request

IsTruncated

String

Whether all versioning objects are returned for a request. If the field value is true, not all versioning objects are returned. If the field value is false, all versioning objects are returned.

KeyMarker

String

Start position for listing versioning objects, which is consistent with that set in the request

VersionIdMarker

String

Version ID to start with for listing versioning objects, which is consistent with that set in the request

NextKeyMarker

String

Object name to start with upon the next request for listing versioning objects in a bucket

NextVersionIdMarker

String

Version to start with upon the next request for listing versioning objects in a bucket. It must be used with the NextKeyMarker parameter.

MaxKeys

String

Maximum number of listed versioning objects, which is consistent with that set in the request

Versions

Array

List of versioning objects. This field contains the following parameters:

  • ETag: MD5 value of the object (type: String)
  • Size: Object length in bytes (type: String)
  • StorageClass: Storage class of the type (type: String)
  • Key: Object name (type: String)
  • VersionId: Object version ID (type: String)
  • IsLatest: Whether the object is of the latest version (type: String). If the parameter value is true, the object is of the latest version.
  • LastModified: Time when the object was last modified (type: String)
  • Owner: Object owner (type: Object)

Owner

Object

Object owner. This field contains the following parameters:

  • Name: Name of the object owner (type: String)
  • ID: DomainId of the object owner (type: String)

DeleteMarkers

Array

List of delete markers

  

Owner

Object

Object owner

  

Name

String

Name of the object owner

ID

String

ID of the domain to which the object owner belongs

Key

String

Object name

VersionId

String

Object version ID

IsLatest

String

Whether the object is of the latest version. If the parameter value is true, the object is of the latest version.

LastModified

String

Time when the last modification was made to the object

CommonPrefixes

Array

List of object name prefixes grouped according to the Delimiter parameter (if specified)

  

Prefix

String

Object name prefix grouped according to the Delimiter parameter

Sample Code

obsClient.listVersions({
       Bucket : 'bucketname',
       Prefix : 'prefix',
       MaxKeys : 100
},(err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
                     console.log('Versions:');
                     for(let j=0;j<result.InterfaceResult.Versions.length;j++){
                           console.log('Version[' + j +  ']:');
                           console.log('Key-->' + result.InterfaceResult.Versions[j]['Key']);
                           console.log('VersionId-->' + result.InterfaceResult.Versions[j]['VersionId']);
                           console.log('IsLatest-->' + result.InterfaceResult.Versions[j]['IsLatest']);
                           console.log('LastModified-->' + result.InterfaceResult.Versions[j]['LastModified']);
                           console.log('ETag-->' + result.InterfaceResult.Versions[j]['ETag']);
                           console.log('Size-->' + result.InterfaceResult.Versions[j]['Size']);
                           console.log('Owner[ID]-->' + result.InterfaceResult.Versions[j]['Owner']['ID']);
                           console.log('Owner[Name]-->' + result.InterfaceResult.Versions[j]['Owner']['Name']);
                           console.log('StorageClass-->' + result.InterfaceResult.Versions[j]['StorageClass']);
                     }
                     console.log('DeleteMarkers:');
                     for(let i=0;i<result.InterfaceResult.DeleteMarkers.length;i++){
                           console.log('DeleteMarker[' + i +  ']:');
                           console.log('Key-->' + result.InterfaceResult.DeleteMarkers[i]['Key']);
                           console.log('VersionId-->' + result.InterfaceResult.DeleteMarkers[i]['VersionId']);
                           console.log('IsLatest-->' + result.InterfaceResult.DeleteMarkers[i]['IsLatest']);
                           console.log('LastModified-->' + result.InterfaceResult.DeleteMarkers[i]['LastModified']);
                           console.log('Owner[ID]-->' + result.InterfaceResult.DeleteMarkers[i]['Owner']['ID']);
                           console.log('Owner[Name]-->' + result.InterfaceResult.DeleteMarkers[i]['Owner']['Name']);
                     }
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});