Updated on 2022-02-10 GMT+08:00

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

func (obsClient ObsClient) CreateBucket(input *CreateBucketInput) (output *BaseModel, err error)

Method Definition If a Signed URL Is Used

func (obsClient ObsClient) CreateBucketWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error)

Request Parameter

Field

Type

Optional or Mandatory

input

*CreateBucketInput

Mandatory

Returned Result

Field

Type

output

*BaseModel

err

error

Sample Code

func main() {
       input := &obs.CreateBucketInput{}
       input.Bucket = "bucketname"
       input.ACL = obs.AclPrivate
       input.StorageClass = obs.StorageClassWarm
       output, err := obsClient.CreateBucket(input)
       if err == nil {
              fmt.Printf("RequestId:%s\n", output.RequestId)
       } else {
              if obsError, ok := err.(obs.ObsError); ok {
                     fmt.Println(obsError.Code)
                     fmt.Println(obsError.Message)
              } else {
                     fmt.Println(err)
              }
       }
}