Updated on 2023-11-09 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. Buckets with the same name can only be created by the same user in the same region. In other cases, creating a bucket with a used name will fail. Each user can create a maximum of 100 buckets.

Method Definition

1. ObsClient->createBucket(array $parameter)
2. ObsClient->createBucketAsync(array $parameter, callable $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 chosen from lowercase letters, digits, hyphens (-), and periods (.), and starts with a digit or letter.
  • 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

LocationConstraint

string

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

Region where a bucket will be created.

This parameter is not required if the endpoint belongs to the default CN North-Beijing1 (cn-north-1) region, but this parameter is a must if the endpoint belongs to any other regions. For the valid regions, see Click Regions and Endpoints. For more information about OBS regions and endpoints, see Regions and Endpoints.

Returned Result

Field

Type

Description

HttpStatusCode

integer

HTTP status code

Reason

string

Reason description

RequestId

string

Request ID returned by the OBS server

Sample Code

try{
       $resp = $obsClient -> createBucket([
              'Bucket' => 'bucketname',
              'ACL' => 'private',
              'StorageClass' => ObsClient::StorageClassStandard
       ]);
       printf("RequestId:%s\n", $resp['RequestId']);
}catch (Obs\Common\ObsException $obsException){
       printf("ExceptionCode:%s\n", $obsException->getExceptionCode());              
       printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage());
}