列举Bucket
更新时间:2022-10-08
列举Bucket
如下代码可以列出用户所有的Bucket:
int listBuckets (Client& client) {
// 获取用户的Bucket列表
ListBucketsRequest listBucketsRequest;
ListBucketsResponse listBucketsResponse;
int ret = client.list_buckets(listBucketsRequest, &listBucketsResponse);
std::vector<BucketSummary> bucketSummaryList = listBucketsResponse.buckets();
if (listBucketsResponse.is_fail()) {
printf("error-message:%s\n", listBucketsResponse.error().message().c_str());
return ret;
}
// 遍历Bucket
for(const BucketSummary& bs : bucketSummaryList){
std::cout << "bucketName: " << bs.name << std::endl;
}
return ret;
}