Create Bucket
Updated at:2025-11-03
Basic workflow
- Create an instance of the BOSClient class.
- To use the BosClient.putBucket method, the bucket name must be provided.
Example code
Plain Text
1let bosClient = new BosClient(credential, clientOptions); // Create BosClient instance
2let location: string;
3try {
4 location = await bosClient.putBucket(bucketName);
5} catch (bosResponse) {
6 logger.error(`errCode: ${bosResponse.error.code}`)
7 logger.error(`requestId: ${bosResponse.error.requestId}`)
8 logger.error(`errMessage: ${bosResponse.error.message}`)
9 logger.error(`statusCode: ${bosResponse.statusCode}`)
10}
Note
- Since bucket names are unique across all regions, ensure that the BucketName does not conflict with existing names in 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 through the above code has private read-write permissions and a storage class of standard (Standard).
