Updated on 2022-02-10 GMT+08:00

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

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.

  

ETag

String

MD5 value of the object (If the object is encrypted using server-side encryption, the ETag is not the MD5 value of the object.)

Size

String

Object size in bytes

Key

String

Object name

LastModified

String

Time when the last modification was made to the object

Owner

Object

Object owner

  

ID

String

ID of the domain to which the object owner belongs

  

StorageClass

String

Storage class of the object

  

Type

String

Whether the object is an appendable 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.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('StorageClass-->' + result.InterfaceResult.Contents[j]['StorageClass']);
                     }
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});