You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Bucket Interface
Listing Buckets (PHP SDK)
Copy page
Download PDF
Listing Buckets (PHP SDK)
A bucket is a container for storing objects. This article presents sample code for listing buckets.​
Sample Code​
You can use TosClient->listBuckets to list buckets. This interface lists buckets across all regions. The following is sample code:​
​
<?php​
​
require_once __DIR__ . '/vendor/autoload.php';​
​
use Tos\TosClient;​
use Tos\Exception\TosClientException;​
use Tos\Exception\TosServerException;​
​
try {​
$client = new TosClient([​
'region' => 'your region',​
'endpoint' => 'your endpoint',​
'ak' => getenv('TOS_ACCESS_KEY'),​
'sk' => getenv('TOS_SECRET_KEY'),​
]);​
​
$output = $client->listBuckets();​
​
echo $output->getRequestId() . PHP_EOL;​
foreach ($output->getBuckets() as $bucket) {​
echo $bucket->getName() . PHP_EOL;​
echo $bucket->getLocation() . PHP_EOL;​
echo $bucket->getCreationDate() . PHP_EOL;​
}​
​
} catch (TosClientException $ex) {​
echo $ex->getMessage() . PHP_EOL;​
} catch (TosServerException $ex) {​
echo $ex->getRequestId() . PHP_EOL;​
echo $ex->getStatusCode() . PHP_EOL;​
echo $ex->getErrorCode() . PHP_EOL;​
}​
​
​
Last updated: 2025.09.23 14:41:21