Bucket Operations

Last updated: 2020-07-03 11:22:26

    Overview

    This document provides an overview of APIs and SDK code samples related to basic bucket operations.

    API Operation Name Operation Description
    GET Service (List Buckets) Querying bucket list Queries the list of all buckets under a specified account
    PUT Bucket Creating a bucket Creates a bucket under a specified account
    HEAD Bucket Checking a bucket and its permission Checks whether a bucket exists and you have permission to access it
    DELETE Bucket Deleting a bucket Deletes an empty bucket under a specified account

    Querying Bucket List

    Feature description

    This API (GET Service (List Buckets)) is used to query the list of all buckets under a specified account.

    Method prototype

    public Guzzle\Service\Resource\Model listBucket(array $args = array())

    Sample request

    try {
        // Request succeeded
        $result = $cosClient->listBuckets();
        print_r($result);
    } catch (\Exception $e) {
        // Request failed
        echo($e);
    }

    Sample return result

    Array
    (
        [data:protected] => Array
            (
                [Owner] => Array
                    (
                        [ID] => qcs::cam::uin/100000000001:uin/100000000001
                        [DisplayName] => 100000000001
                    )
    
                [Buckets] => Array
                    (
                        [0] => Array
                            (
                                [Name] => examplebucket-1250000000
                                [Location] => ap-beijing
                                [CreationDate] => 2016-07-29T03:09:54Z
                            )
    
                        [1] => Array
                            (
                                [Name] => examplebucket2-1250000000
                                [Location] => ap-beijing
                                [CreationDate] => 2017-08-02T04:00:24Z
                            )
    
                    )
    
                [RequestId] => NWE3YzgxZmFfYWZhYzM1MGFfMzc3MF9iOGY5OQ==
            )
    
    )

    Returned result description

    Parameter Name Parent Node Description Type
    Owner None Bucket owner information Array
    ID Owner Bucket owner ID String
    DisplayName Owner Bucket owner name String
    Buckets None Bucket list Array
    Bucket Buckets Bucket information Array
    Name Bucket Bucket name String
    Location Bucket Bucket region name String
    CreationDate Bucket Bucket creation time String

    Creating Bucket

    Feature description

    This API (PUT Bucket) is used to create a bucket under a specified account.

    Method prototype

    public Guzzle\Service\Resource\Model createBucket(array $args = array());

    Sample request

    try {
        $bucket = "examplebucket-1250000000"; // Bucket name in the format of `BucketName-APPID`
        $result = $cosClient->createBucket(array('Bucket' => $bucket));
        // Request succeeded
        print_r($result);
    } catch (\Exception $e) {
        // Request failed
        echo($e);
    }

    Parameter description

    Parameter Name Parent Node Description Type
    Bucket None Bucket name in the format of BucketName-APPID String

    Checking Bucket and Its Permission

    Feature description

    This API (HEAD Bucket) is used to confirm whether a bucket exists and you have permission to access it.

    Method prototype

    public Guzzle\Service\Resource\Model headBucket(array $args = array());

    Sample request

    try {
        $result = $cosClient->headBucket(array(
            'Bucket' => 'examplebucket-1250000000' // Format: BucketName-APPID
        )); 
        // Request succeeded
        print_r($result);
    } catch (\Exception $e) {
        // Request failed
        echo($e);
    }

    Parameter description

    Parameter Name Parent Node Description Type
    Bucket None Bucket name in the format of BucketName-APPID String

    Deleting Bucket

    Feature description

    This API is used to delete an empty bucket under a specified account.

    Method prototype

    public Guzzle\Service\Resource\Model deleteBucket(array $args = array());

    Sample request

    try {
        $result = $cosClient->deleteBucket(array(
            'Bucket' => 'examplebucket-1250000000' // Format: BucketName-APPID
        )); 
        // Request succeeded
        print_r($result);
    } catch (\Exception $e) {
        // Request failed
        echo($e);
    }

    Parameter description

    Parameter Name Parent Node Description Type
    Bucket None Bucket name in the format of BucketName-APPID String

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help