• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Node.js SDK)
  4. Bucket-Related APIs
  5. PUT Bucket

PUT Bucket

API Description

You can use this API to create a bucket and name it as you specify. The created bucket name must be unique in OBS. If a user repeatedly creates buckets with the same name in one region, status code 200 is returned. In other cases, status code 409 is returned. Each user can create a maximum of 100 buckets.

Method Definition

ObsClient.createBucket(parameter, callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

String

Mandatory

Bucket name.

A bucket name must comply with the following rules:
  • Contains 3 to 63 characters, starts with a digit or letter, and supports only lowercase letters, digits, hyphens (-), and periods (.)
  • Cannot be an IP-like address.
  • Cannot start or end with a hyphen (-) or period (.).
  • Cannot contain two consecutive periods (.), for example, my..bucket.
  • Cannot contain periods (.) and hyphens (-) adjacent to each other, for example, my-.bucket or my.-bucket.

ACL

String

Optional

Pre-defined access control policy that can be specified during bucket creation. Possible values are:

  • ObsClient.enums.AclPrivate
  • ObsClient.enums.AclPublicRead
  • ObsClient.enums.AclPublicReadWrite
  • ObsClient.enums.AclAuthenticatedRead
  • ObsClient.enums.AclBucketOwnerRead
  • ObsClient.enums.AclBucketOwnerFullControl
  • ObsClient.enums.AclLogDeliveryWrite

StorageClass

String

Optional

Bucket storage class that can be specified during bucket creation. Possible values are:

  • ObsClient.enums.StorageClassStandard
  • ObsClient.enums.StorageClassWarm
  • ObsClient.enums.StorageClassCold

Location

String

Mandatory unless the region where the OBS service resides is not the default region.

Bucket location

For details about OBS regions and endpoints, see Regions and Endpoints.

Returned Result (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

Sample Code

obsClient.createBucket({
       Bucket : 'bucketname',
       ACL : obsClient.enums.AclPrivate,
       StorageClass : obsClient.enums.StorageClassCold
}, (err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});