• Object Storage Service

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

Obtain Bucket Metadata

API Description

You can use this API to send a HEAD request to a bucket to obtain the bucket metadata such as the storage class and CORS rules (if set).

Method Definition

ObsClient.getBucketMetadata(bucketName, origin, requestHeaders)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

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

Returned Result

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

GetBucketMetadataResponse

Response result of Obtain Bucket Metadata

Sample Code

try:
    resp = obsClient.getBucketMetadata('bucketname', 'http://www.a.com', 'x-obs-header') 
      
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
        print('storageClass:', resp.body.storageClass) 
        print('accessContorlAllowOrigin:', resp.body.accessContorlAllowOrigin) 
        print('accessContorlMaxAge:', resp.body.accessContorlMaxAge)     
        print('accessContorlExposeHeaders:', resp.body.accessContorlExposeHeaders)    
        print('accessContorlAllowMethods:', resp.body.accessContorlAllowMethods) 
        print('accessContorlAllowHeaders:', resp.body.accessContorlAllowHeaders) 
    else: 
        print('status:', resp.status)
except:
    import traceback
    print(traceback.format_exc())