• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Python SDK)
  4. Objects-Related APIs
  5. Obtain Object Metadata

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(bucketName, objectKey, versionId, sseHeader, origin, requestHeaders)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

objectKey

str

Mandatory

Object name

versionId

str

Optional

Object version ID

origin

str

Optional

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

requestHeaders

str

Optional

HTTP headers in a cross-domain request

sseHeader

SseCHeader

Optional

Header for server-side decryption

Returned Result

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

GetObjectMetadataResponse

Response result of Obtain Object Metadata

Sample Code

try:
    resp = obsClient.getObjectMetadata('bucketname', 'objectkey') 
          
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
        print('etag:', resp.body.etag) 
        print('lastModified:', resp.body.lastModified) 
        print('contentType:', resp.body.contentType) 
        print('contentLength:', resp.body.contentLength) 
    else: 
        print('status:', resp.status)
except:
    import traceback
    print(traceback.format_exc())