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

HEAD Bucket

API Description

You can use this API to check whether a bucket exists. If the HTTP status code in the thrown exception is 200, the bucket exists. If the HTTP status code is 404, the bucket does not exist.

Method Definition

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

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

string

Mandatory

Bucket name

Returned Result

Field

Type

Description

HttpStatusCode

integer

HTTP status code

Reason

string

Reason description

RequestId

string

Request ID returned by the OBS server

Sample Code

try{
       $resp = $obsClient -> headBucket([
              'Bucket' => 'bucketname'
       ]);
       printf("RequestId:%s\n", $resp['RequestId']);
       printf("Bucket exists\n");
}catch (Obs\Common\ObsException $obsException){
       if($obsException->getStatusCode() === 404){
              printf("Bucket does not exist\n");
       }else{
              printf("StatusCode:%d\n", $obsException->getStatusCode());
       }              
}