更新时间:2021-03-18 GMT+08:00
分享

判断桶是否存在

功能说明

判断桶是否存在,抛出异常中HTTP状态码为200表明桶存在,否则返回404表明桶不存在。

方法定义

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

请求参数

字段名

类型

约束

说明

Bucket

string

必选

桶名。

返回结果

字段名

类型

说明

HttpStatusCode

integer

HTTP状态码。

Reason

string

HTTP文本描述。

RequestId

string

OBS服务端返回的请求ID。

代码样例

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

    相关文档

    相关产品