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

Torch Object Storage

Copy page
Download PDF
Bucket Interface
Creating a Bucket (PHP SDK)
Copy page
Download PDF
Creating a Bucket (PHP SDK)
A Bucket (桶) is the globally unique namespace in TOS, functioning as a data container for storing Object data. The name of a newly created bucket must be unique within TOS.​
Sample Code​
You can create a new bucket using TosClient->createBucket. The following is a sample code:​
​
<?php​
​
require_once __DIR__ . '/vendor/autoload.php';​
​
use Tos\TosClient;​
use Tos\Exception\TosClientException;​
use Tos\Exception\TosServerException;​
use Tos\Model\CreateBucketInput;​
use Tos\Model\Enum;​
​
try {​
$client = new TosClient([​
'region' => 'your region',​
'endpoint' => 'your endpoint',​
'ak' => getenv('TOS_ACCESS_KEY'),​
'sk' => getenv('TOS_SECRET_KEY'),​
]);​
​
$input = new CreateBucketInput('bucket-test');​
$input->setACL(Enum::ACLPublicRead);​
$input->setAzRedundancy(Enum::AzRedundancySingleAz);​
$input->setStorageClass(Enum::StorageClassIa);​
$output = $client->createBucket($input);​
​
echo $output->getRequestId() . 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