View the region to which a bucket belongs
Updated at:2025-11-03
View the region to which a bucket belongs
Bucket Location refers to Bucket Region. For details on regions supported by Baidu AI Cloud, refer to [Region Selection Guide](Reference/Region Selection Instructions/Region.md).
The following code can retrieve the bucket's location information:
C++
1Client client (ak, sk, config);
2ListBucketsRequest listBucketsRequest;
3ListBucketsResponse listBucketsResponse;
4int ret = client.list_buckets(listBucketsRequest, &listBucketsResponse)
5std::vector<BucketSummary> bucketSummaryList = listBucketsResponse.buckets();
6if (listBucketsResponse.is_fail()) {
7 printf("error-message:%s\n", listBucketsResponse.error().message().c_str());
8 return ;
9}
10for(const BucketSummary& bs : bucketSummaryList){
11 std::cout << "name: " << bs.name <<
12 " location: " << bs.location << std::endl;
13}
14GetBucketLocationRequest getBucketLocationRequest("bucketName");
15GetBucketLocationResponse getBucketLocationResponse;
16ret = client.get_bucket_location(getBucketLocationRequest,
17 &getBucketLocationResponse);
18if (getBucketLocationResponse.is_fail()) {
19 printf("error-message:%s\n", response.error().message().c_str());
20 return;
21}
22std::cout << "location: " << getBucketLocationResponse.location() << std::endl;
