Create Bucket
Updated at:2025-11-03
Create Bucket
The following code can be used to create a bucket:
C++
1int createBucket (Client& client, const std::string& bucketName) {
2 // Create a new bucket
3 PutBucketRequest request(bucketName);
4 PutBucketResponse response;
5 int ret = client.put_bucket(request, &response);
6 if (ret !=0) {
7 return ret;
8 }
9 if (response.is_fail()) {
10 printf("error-message:%s\n", response.error().message().c_str());
11 }
12 return ret;
13}
14int main() {
15 std::sting ak = "ak";
16 std::string sk = "sk";
17 Client client(ak, sk);
18 int ret = createBucket(client, "bucketName");
19 std::string ret_info = stringfy_ret_code(ret);
20 std::cout << ret_info << std::endl;
21}
Note: Since the bucket name is unique across all regions, it is necessary to ensure that the bucketName is not the same as the BucketName on all other regions.
Bucket naming follows the following conventions:
- Only lowercase letters, numbers, and hyphens (-) are allowed.
- Must start with a lowercase letter or a number.
- Length should range between 4-63 bytes.
The bucket created using the above code has private read-write permissions and a standard (Standard) storage class.
