• Object Storage Service

  1. Help Center
  2. Object Storage Service
  3. Developer Guide (PHP SDK)
  4. Bucket Management
  5. Listing Buckets

Listing Buckets

You can call ObsClient->listBuckets to list buckets. Sample code is as follows:

// Import the third-party open source libraries.
require 'vendor/autoload.php';
// Import the SDK code library.
require 'obs-autoloader.php';
// Declare the namespace.
use Obs\S3\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient([
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://yourdomainname'

$resp = $obsClient->listBuckets();

printf("RequestId:%s\n", $resp['RequestId']);
printf("Owner[ID]:%s\n", $resp['Owner']['ID']);
printf("Owner[DisplayName]:%s\n", $resp['Owner']['DisplayName']);
foreach ($resp['Buckets'] as $index => $bucket){
       printf("Buckets[%d]\n", $index + 1);
       printf("Name:%s\n", $bucket['Name']);
       printf("CreationDate:%s\n", $bucket['CreationDate']);

Obtained bucket names are listed in the lexicographical order.