• Object Storage Service

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

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());
       }              
}