• Object Storage Service

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

Marker

String

Optional

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

MaxKeys

Number

Optional

Maximum number of 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.)

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

IsTruncated

String

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

Prefix

String

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

Marker

String

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

NextMarker

String

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

MaxKeys

String

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

Contents

Array

Object list. This field contains the following parameters:

  • ETag: MD5 value of the object (type: String). If the value type is String and the object is encrypted using server-side encryption, ETag is not the MD5 value of the object.
  • Size: Object length in bytes (type: String)
  • StorageClass: Storage class of the object (type: String)
  • Key: Object name (type: String)
  • LastModified: Time when the object was last modified (type: String)
  • Owner: Object owner (type: Object)

Owner

Object

Object owner. The field contains the following parameters:

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

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.listObjects({
       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);
                     for(let j=0;j<result.InterfaceResult.Contents.length;j++){
                           console.log('Contents[' + j +  ']:');
                           console.log('Key-->' + result.InterfaceResult.Contents[j]['Key']);
                           console.log('LastModified-->' + result.InterfaceResult.Contents[j]['LastModified']);
                           console.log('ETag-->' + result.InterfaceResult.Contents[j]['ETag']);
                           console.log('Size-->' + result.InterfaceResult.Contents[j]['Size']);
                           console.log('Owner[ID]-->' + result.InterfaceResult.Contents[j]['Owner']['ID']);
                           console.log('Owner[Name]-->' + result.InterfaceResult.Contents[j]['Owner']['Name']);
                           console.log('StorageClass-->' + result.InterfaceResult.Contents[j]['StorageClass']);
                     }
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});