Updated on 2023-03-16 GMT+08:00

Obtain Object Metadata

API Description

You can use this API to send a HEAD request to the object of a specified bucket to obtain its metadata.

Method Definition

ObsClient.getObjectMetadata

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

String

Mandatory

Bucket name

Key

String

Mandatory

Object name

VersionId

String

Optional

Object version ID

Origin

String

Optional

Origin of the cross-domain request specified by the pre-request. Generally, it is a domain name.

RequestHeader

String

Optional

HTTP headers in the cross-domain request

SseC

String

Optional

Algorithm used in SSE-C decryption. The value can be:

  • AES256

SseCKey

Buffer

Optional

Key used in SSE-C decryption, which is calculated by using AES256.

Returned Result (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

LastModified

String

Time when the last modification was made to the object

ContentLength

String

Object size in bytes

ContentType

String

MIME type of the object

ETag

String

Object ETag

VersionId

String

Object version ID

WebsiteRedirectLocation

String

Location where the object is redirected to, when the bucket is configured with website hosting

StorageClass

String

Storage class of the object. When the storage class is OBS Standard, the value is null.

Restore

String

Restore status of the object in the OBS Archive storage class

AllowOrigin

String

If Origin in the request meets the CORS rules of the bucket, AllowedOrigin in the CORS rules is returned.

AllowHeader

String

If AccessControlRequestHeaders in the request meets the CORS rules of the bucket, AllowedHeader in the CORS rules is returned.

AllowMethod

String

AllowedMethod in the CORS rules of the bucket

ExposeHeader

String

ExposeHeader in the CORS rules of the bucket

MaxAgeSeconds

String

MaxAgeSeconds in the CORS rules of the bucket

SseKms

String

Algorithm used in SSE-KMS decryption

SseKmsKey

String

Master key used in SSE-KMS decryption

SseC

String

Algorithm used in SSE-C decryption

SseCKeyMd5

String

MD5 value of the key used in SSE-C decryption

Expiration

String

Expiration details

Metadata

Object

Customized metadata of the object

ObjectType

String

Whether the object is an appendable object

NextPosition

String

Start position for next appending

Sample Code

obsClient.getObjectMetadata({
       Bucket:'bucketname',
       Key : 'objectkey'
},(err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
                     console.log('ETag-->' + result.InterfaceResult.ETag);
                     console.log('VersionId-->' + result.InterfaceResult.VersionId);
                     console.log('ContentLength-->' + result.InterfaceResult.ContentLength);
                     console.log('Expiration-->' + result.InterfaceResult.Expiration);
                     console.log('Metadata-->' + JSON.stringify(result.InterfaceResult.Metadata));
                     console.log('LastModified-->' + result.InterfaceResult.LastModified);
                     console.log('StorageClass-->' + result.InterfaceResult.StorageClass);
              }else{
                     console.log('Status-->' + result.CommonMsg.Status);
              }
       }
});