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.

Bucket-Related API functions of ObsClient are case insensitive. For example, ObsClient.createBucket and ObsClient.CreateBucket indicate the same function.

Method Definition

ObsClient.createBucket

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 the bucket creation

StorageClass

String

Optional

Bucket storage class that can be specified during the bucket creation

Location

String

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

Bucket location

This parameter is not required if the endpoint belongs to the default North China 1 region (cn-north-1). This parameter is a must if the endpoint belongs to any other regions. Click here to query currently valid regions. 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);
              }
       }
});