Overview
This document provides sample code for quickly checking whether a bucket exists.
The sample code actually calls the HEAD Bucket COS API and is a simplified version of the API. In addition to checking whether a bucket exists, HEAD Bucket
also checks whether you have permission to access the bucket. Possible scenarios are as follows:
If the bucket exists and you have permission to read it, HTTP status code 200 will be returned.
If you do not have permission to read the bucket, HTTP status code 403 will be returned.
If the bucket does not exist, HTTP status code 404 will be returned.
Checking Whether a Bucket Exists
Feature description
This API is used to check whether a bucket exists.
Method prototype
public Guzzle\\Service\\Resource\\Model doesBucketExist(array $args = array());
Sample code
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$secretId = "SECRETID";
$secretKey = "SECRETKEY";
$region = "ap-beijing";
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https',
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));
try {
$result = $cosClient->doesBucketExist(
'examplebucket-125000000'
); ;
print_r($result);
} catch (\\Exception $e) {
echo($e);
}
Was this page helpful?