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

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

1. ObsClient->getBucketMetadata(array $parameter)
2. ObsClient->getBucketMetadata(array $parameter, callable $callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

string

Mandatory

Bucket name

Origin

string

Optional

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

RequestHeader

string

Optional

HTTP header in a cross-domain request

Returned Result

Field

Type

Description

HttpStatusCode

integer

HTTP status code

Reason

string

Reason description

RequestId

string

Request ID returned by the OBS server

Location

string

Bucket location

StorageClass

string

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

AllowOrigin

string

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

AllowHeader

string

If RequestHeader in the request meets the CORS rules of the server, AllowedHeader in the CORS rules is returned.

AllowMethod

string

AllowedMethod in the CORS rules of the server

ExposeHeader

string

ExposeHeader in the CORS rules of the server

MaxAgeSeconds

integer

MaxAgeSeconds in the CORS rules of the server

Sample Code

try{
       $resp = $obsClient -> getBucketMetadata([
              'Bucket' => 'bucketname',
              'Origin' => 'http://www.a.com',
              'RequestHeader' => 'x-obs-header'
       ]);
       printf("RequestId:%s\n", $resp['RequestId']);
       printf("StorageClass:%s\n", $resp['StorageClass']);
       printf("AllowOrigin:%s\n", $resp['AllowOrigin']);
       printf("AllowHeader:%s\n", $resp['AllowHeader']);
       printf("AllowMethod:%s\n", $resp['AllowMethod']);
       printf("ExposeHeader:%s\n", $resp['ExposeHeader']);
       printf("MaxAgeSeconds:%s\n", $resp['MaxAgeSeconds']);
}catch (Obs\Common\ObsException $obsException){
       printf("StatusCode:%s\n", $obsException->getStatusCode());              
}