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

Torch Object Storage

Copy page
Download PDF
Basic Bucket Interface
Obtaining Bucket Region (C++ SDK)
Copy page
Download PDF
Obtaining Bucket Region (C++ SDK)
A bucket is the globally unique namespace in TOS, functioning as a data container for storing object data. This article describes how to obtain the region where a bucket is located.​
Precautions​
  • Only the bucket owner can view the region where the bucket is located.​
  • When managing buckets and objects within buckets using the TOS C++ SDK, you must use the domain name of the region where the bucket is located. For more information about regions and access domain names, see Regions and Access Domain Names.​
Sample Code​
The following code is used to obtain the region (referred to as Region or Location) where the bucket examplebucket is located.​
​
#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);​
​
​
GetBucketLocationInput input(bucketName);​
auto output = client.getBucketLocation(input);​
if (!output.isSuccess()) {​
​
std::cout << "GetBucketLocation failed." << output.error().String() << std::endl;​
​
CloseClient();​
return -1;​
}​
​
std::cout << "GetBucketLocation success, "​
<< "the bucket region:" << output.result().getRegion()​
<< "the bucket ExtranetEndpoint:" << output.result().getExtranetEndpoint()​
<< "the bucket IntranetEndpoint:" << output.result().getIntranetEndpoint()​
<< std::endl;​
​
​
CloseClient();​
return 0;​
}​
​
​
Last updated: 2025.09.25 14:22:45