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

Torch Object Storage

Copy page
Download PDF
Basic Bucket Interface
List Buckets (C++ SDK)
Copy page
Download PDF
List Buckets (C++ SDK)
Obtain the list of storage buckets (Bucket) using ListBuckets. You can list all storage spaces under every region of the current account that meet the specified criteria.​
Precautions​
  • This interface returns all buckets across all regions for the current account.​
Sample Code​
The following code enumerates all buckets across all regions for the current account.​
​
#include "TosClientV2.h"​
using namespace VolcengineTos;​
​
int main(void){​
​
​
std::string region = "Your Region";​
std::string accessKey = std::getenv("TOS_ACCESS_KEY");​
std::string secretKey = std::getenv("TOS_SECRET_KEY");​
​
std::string bucketName = "examplebucket";​
​
​
InitializeClient();​
​
TosClientV2 client(region, accessKey, secretKey);​
​
​
ListBucketsInput input;​
auto output = client.listBuckets(input);​
if (!output.isSuccess()) {​
​
std::cout << "ListBuckets failed." << output.error().String() << std::endl;​
​
CloseClient();​
return -1;​
}​
​
std::cout << "ListBuckets Success, the bucket count is :" << output.result().getBuckets().size() << std::endl;​
std::cout << "Bucket Info is" << std::endl;​
for (auto& result : output.result().getBuckets()) {​
std::cout << "bucketName: " << result.getName() << " location: " << result.getLocation()​
<< " createDate: " << result.getCreationDate() << std::endl;​
}​
​
CloseClient();​
return 0;​
}​
​
Relevant Documentation​
For API documentation on listing buckets, refer to ListBuckets.​
Last updated: 2025.09.25 14:22:45