• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (PHP 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. 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 bucket creation. Possible values are:

  • ObsClient::AclPrivate
  • ObsClient::AclPublicRead
  • ObsClient::AclPublicReadWrite
  • ObsClient::AclAuthenticatedRead
  • ObsClient::AclBucketOwnerRead
  • ObsClient::AclBucketOwnerFullControl
  • ObsClient::AclLogDeliveryWrite

StorageClass

string

Optional

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

  • ObsClient::StorageClassStandard
  • ObsClient::StorageClassWarm
  • ObsClient::StorageClassCold

LocationConstraint

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

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());
}