Bucket Management

Last updated: 2020-07-01 10:39:38
This document is currently invalid. Please refer to the documentation page of the product.

    Overview

    This document provides an overview of APIs and SDK code samples related to cross-origin access, lifecycle, bucket policies, tag management, versioning, and cross-region replication.

    Cross-origin access

    API Operation Description
    PUT Bucket cors Setting cross-origin access configuration Sets the cross-origin access permissions of a bucket
    GET Bucket cors Querying cross-origin access configuration Queries the cross-origin access configuration of a bucket
    DELETE Bucket cors Deleting cross-origin access configuration Deletes the cross-origin access configuration of a bucket

    Lifecycle

    API Operation Description
    PUT Bucket lifecycle Setting lifecycle Sets the lifecycle management configuration of a bucket
    GET Bucket lifecycle Querying lifecycle Queries the lifecycle management configuration of a bucket
    DELETE Bucket lifecycle Deleting lifecycle Deletes the lifecycle management configuration of a bucket

    Bucket policies

    API Operation Description
    PUT Bucket policy Setting a bucket policy Sets a permission policy for a specified bucket
    GET Bucket policy Querying bucket policies Queries the permission policies of a specified bucket
    DELETE Bucket policy Deleting bucket policies Deletes the permission policies of a specified bucket

    Tag management

    API Operation Description
    PUT Bucket tagging Setting bucket tags Sets tags for an existing bucket
    GET Bucket tagging Querying bucket tags Queries the existing tags of a specified bucket
    DELETE Bucket tagging Deleting bucket tags Deletes the tags of a specified bucket

    Versioning

    API Operation Description
    PUT Bucket versioning Setting versioning Sets the versioning configuration of a bucket
    GET Bucket versioning Querying versioning Queries the versioning information of a bucket

    Cross-region replication

    API Operation Description
    PUT Bucket replication Setting cross-region replication Sets the cross-region replication rules of a bucket
    GET Bucket replication Querying cross-region replication Queries the cross-region replication rules of a bucket
    DELETE Bucket replication Deleting cross-region replication Deletes the cross-region replication rules of a bucket

    Cross-origin access

    Setting cross-origin configuration

    1. Ensure that the bucket supports cross-origin access before configuring. Cross-origin access can be configured on the console. For details, see Getting Started.
    2. Make sure changing the cross-origin access configuration does not affect cross-origin requests under the current origin.

    Feature description

    This API is used to configure the cross-origin resource sharing (CORS) permission of a bucket. You can set the configuration by passing in a configuration file in XML format of up to 64 KB in size. By default, the bucket owner has the permission to use this API and can grant such permission to other users.

    Use case

    cos.putBucketCors({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
        CORSRules: [{
            "AllowedOrigin": ["*"],
            "AllowedMethod": ["GET", "POST", "PUT", "DELETE", "HEAD"],
            "AllowedHeader": ["*"],
            "ExposeHeader": ["ETag", "x-cos-acl", "x-cos-version-id", "x-cos-delete-marker", "x-cos-server-side-encryption"],
            "MaxAgeSeconds": "5"
        }]
    },function (err,data) {
        console.log(err || data);
    });

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes
    CORSRules List of all the information on CORS configuration ObjectArray No
    - ID Sets the rule ID String No
    - AllowedMethods Allowed HTTP operations. Enumerated values: GET, PUT, HEAD, POST, DELETE StringArray Yes
    - - AllowedOrigins Allowed origin in the format: protocol://domain name[:port number],
    such as http://www.qq.com. Wildcard * is supported
    StringArray Yes
    - AllowedHeaders Tells the server what custom HTTP request headers can be used for subsequent requests when the OPTIONS request is sent. Wildcard * is supported StringArray No
    - ExposeHeaders Sets the user-defined header information from the server side that the browser can receive StringArray No
    - MaxAgeSeconds Sets the validity period of the OPTIONS request result String No

    Callback function description

    },function (err,data) {
    Parameter Name Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object

    Querying a cross-origin access configuration

    Feature description

    This API is used to query the cross-origin resource sharing (CORS, a W3C standard) configuration of a bucket. By default, the bucket owner has the permission to use this API and can grant such permission to other users.

    Use case

    cos.getBucketCors({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
    },function (err,data) {
        console.log(err || data);
    });

    Sample response

    {
        "CORSRules": [{
            "MaxAgeSeconds": "5",
            "AllowedOrigins": ["*"],
            "AllowedHeaders": ["*"],
            "AllowedMethods": ["GET", "POST", "PUT", "DELETE", "HEAD"],
            "ExposeHeaders": ["ETag", "Content-Length", "x-cos-acl", "x-cos-version-id", "x-cos-request-id", "x-cos-delete-marker", "x-cos-server-side-encryption"]
        }],
        "statusCode": 200,
        "headers": {}
    }

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes

    Callback function description

    },function (err,data) {
    Parameter Name Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - CORSRules List of all the information on CORS configuration ObjectArray
    - AllowedMethods Allowed HTTP operations. Enumerated values: GET, PUT, HEAD, POST, DELETE StringArray
    - - AllowedOrigins Allowed origin in the format of protocol://domain name[:port number],
    such as http://www.qq.com. Wildcard * is supported
    StringArray
    - AllowedHeaders Tells the server what custom HTTP request headers can be used for subsequent requests when the OPTIONS request is sent. Wildcard * is supported StringArray
    - - ExposeHeaders Sets the user-defined header information from the server side that the browser can receive StringArray
    - - MaxAgeSeconds Sets the validity period of the OPTIONS request result String
    - - ID Configures the rule ID String

    Deleting a cross-origin access configuration

    Feature description

    This API is used to delete the cross-origin access configuration of a bucket.

    1. Please note that if you delete the cross-origin access configuration of the current bucket, all cross-origin access requests will fail.
    2. We do not recommend using this method in a browser.

    Use case

    cos.deleteBucketCors({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
    },function (err,data) {
        console.log(err || data);
    });

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes

    Callback function description

    },function (err,data) {
    Parameter Name Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object

    Lifecycle

    Setting a lifecycle configuration

    Feature description

    This API is used to set the lifecycle configuration of a bucket.

    Use case

    Sample 1. Transition objects to Standard_IA storage class 30 days after upload

    cos.putBucketLifecycle({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
        Rules: [{
            "ID": "1",
            Status: "Enabled",
            "Filter": {},
            "Transition": {
                "Days": "30",
                "StorageClass": "STANDARD_IA"
            }
        }],
    },function (err,data) {
        console.log(err || data);
    });

    Sample 2. Transition objects with the specified directory prefix dir/ to archive storage class 90 days after upload

    cos.putBucketLifecycle({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
        Rules: [{
            "ID": "2",
            "Filter": {
                "Prefix": "dir/",
            },
            Status: "Enabled",
            "Transition": {
                "Days": "90",
                "StorageClass": "ARCHIVE"
            }
        }],
    },function (err,data) {
        console.log(err || data);
    });

    Sample 3: Clean up the expired file delate markers 180 days after upload.

    cos.putBucketLifecycle({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
        Rules: [{
            "ID": "3",
            Status: "Enabled",
            "Filter": {},
            "Expiration": {
                "Days": "180"
            }
        }],
    },function (err,data) {
        console.log(err || data);
    });

    Sample 4. Delete incomplete multipart uploads 30 days after upload

    cos.putBucketLifecycle({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
        Rules: [{
            "ID": "4",
            Status: "Enabled",
            "Filter": {},
            "AbortIncompleteMultipartUpload": {
                "DaysAfterInitiation": "30"
            }
        }],
    },function (err,data) {
        console.log(err || data);
    });

    Sample 5: Deposit the past version in the cloud storage archive 30 days after it is generated.

    cos.putBucketLifecycle({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
        Rules: [{
            "ID": "5",
            Status: "Enabled",
            "Filter": {},
            "NoncurrentVersionTransition": {
                "NoncurrentDays": "30",
                "StorageClass": 'ARCHIVE'
            }
        }],
    },function (err,data) {
        console.log(err || data);
    });

    Parameter description

    Parameter Name                                                                      Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes
    Rules List of specific lifecycle rules ObjectArray Yes
    - ID Unique rule ID String Yes
    - Status Rule status; enumerated values: Enabled, Disabled String Yes
    - Filter Specifies the filter Object Yes
    - - - Prefix Object prefix to be matched with the rule String No
    - Transition Rule conversion attributes, indicating when the object storage level is converted to Standard_IA or Archive Object No
    - - Days Indicates how many days after which the object was last modified that the action corresponding to the rule will be executed. The value must be a non-negative integer, and a maximum of 3650 days is supported Number Yes
    StorageClass Indicates the storage class of the object after transition; enumerated values: STANDARD, STANDARD_IA, ARCHIVE. Default value: STANDARD String No
    - NoncurrentVersionTransition Specifies past object version conversion attributes ObjectArray No
    - - NoncurrentDays Indicates that the past object version is converted after the number of effective days determined by this value Number Yes
    StorageClass Indicates the storage class of the object after transition; enumerated values: STANDARD, STANDARD_IA, ARCHIVE. Default value: STANDARD String Yes
    - Expiration Rule expiration attributes Object No
    - - ExpiredObjectDeleteMarker Deletes expired object delete markers, enumerated values are true and false, cannot coexist with Days Boolean Yes
    - - Days Specifies the number of days after which the object was last modified that the action corresponding to the rule will be deleted, cannot coexist with ExpiredObjectDeleteMarker Number Yes
    - AbortIncompleteMultipartUpload Indicates to delete incomplete multipart uploads Object No
    - - DaysAfterInitiation Incomplete multipart uploads are deleted after the number of effective days determined by this value; the computation of this value starts from the time the file was uploaded and must be a positive integer Number Yes

    Callback function description

    },function (err,data) {
    Parameter Name Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object

    Querying a lifecycle configuration

    Feature description

    This API is used to query the lifecycle management configuration of a bucket.

    Use case

    cos.getBucketLifecycle({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
    },function (err,data) {
        console.log(err || data);
    });

    Sample response

    {
        "Rules": {
            "ID": "1",
            "Filter": "",
            Status: "Enabled",
            "Transition": {
                "Days": "30",
                "StorageClass": "STANDARD_IA"
            }
        }, {
            "ID": "2",
            "Filter": {
                "Prefix": "dir/"
            },
            Status: "Enabled",
            "Transition": {
                "Days": "90",
                "StorageClass": "ARCHIVE"
            }
        }, {
            "ID": "3",
            "Filter": "",
            Status: "Enabled",
            "Expiration": {
                "Days": "180"
            }
        }, {
            "ID": "4",
            "Filter": "",
            Status: "Enabled",
            "AbortIncompleteMultipartUpload": {
                "DaysAfterInitiation": "30"
            }
        }, {
            "ID": "5",
            "Filter": "",
            Status: "Enabled",
            "NoncurrentVersionTransition:": {
                "NoncurrentDays": "30",
                "StorageClass": "ARCHIVE"
            }
        }],
        "statusCode": 200,
        "headers": {}
    }

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Domain Name Access String Yes

    Callback function description

    },function (err,data) {
    Parameter Name                                                 Parameter Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    - Rules List of specific lifecycle rules ObjectArray
    - - ID Unique rule ID String
    - Status Rule status; enumerated values: Enabled, Disabled String
    - - Filter Specifies the filter Object
    - - - Prefix Key prefix to be matched with the rule String
    - - Transition Rule conversion attributes, indicating when the object storage level is converted to Standard_IA or Archive ObjectArray
    - - - Days Specifies how many days after which the object was last modified that the action corresponding to the rule will be executed. This value must be a non-negative integer, and a maximum of 3650 days is supported
    StorageClass Indicates the storage class of the object after transition; enumerated values: STANDARD, STANDARD_IA, ARCHIVE. Default value: STANDARD String
    - - NoncurrentVersionTransition Specifies past object version conversion attributes ObjectArray
    - - - NoncurrentDays Indicates that the past object version is converted after the number of effective days determined by this value Number
    StorageClass Indicates the storage class of the object after transition; enumerated values: STANDARD, STANDARD_IA, ARCHIVE. Default value: STANDARD String
    - - Expiration Rule expiration attributes Object
    - - - ExpiredObjectDeleteMarker Deletes expired object delete markers, enumerated values are true and false, cannot coexist with Days Boolean
    - - - Days Specifies the number of days after which the object was last modified that the action corresponding to the rule will be deleted, cannot coexist with ExpiredObjectDeleteMarker Number
    - AbortIncompleteMultipartUpload Indicates to delete incomplete multipart uploads Object
    - - - DaysAfterInitiation Incomplete multipart uploads are deleted after the number of effective days determined by this value; the computation of this value starts from the time the file was uploaded and must be a positive integer Number

    Deleting a lifecycle configuration

    Feature description

    This API is used to delete the lifecycle configuration of a bucket.

    Use case

    cos.deleteBucketLifecycle({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
    },function (err,data) {
        console.log(err || data);
    });

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes

    Callback function description

    },function (err,data) {
    Parameter Name Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object

    Bucket policies

    Setting bucket policies

    Feature description

    This API is used to set permission policies for a specified bucket.

    Use case

    cos.putBucketPolicy({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
        Policy: {
            "version": "2.0",
            "Statement": [{
                "Effect": "allow",
                "Principal": {
                    "qcs": ["qcs::cam::uin/100000000001:uin/100000000001"]
                },
                "Action": [
                    "name/cos:PutObject",
                    "name/cos:InitiateMultipartUpload",
                    "name/cos:ListMultipartUploads",
                    "name/cos:ListParts",
                    "name/cos:UploadPart",
                    "name/cos:CompleteMultipartUpload"
                ],
                "Resource": ["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],
            }]
        },
    },function (err,data) {
        console.log(err || data);
    });

    Parameter description

    Parameter Name             Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes
    Policy Permission policy. For more information, see Cloud Access Management Practices > Policy Syntax Object Yes
    - version Version number, fixed as 2.0 String Yes
    - statement List of permission policy statements ObjectArray Yes
    - - effect Effect; enumerated values: allow, deny String Yes
    - - principal Identity information ObjectArray Yes
    - - - qcs ID string
    Format: qcs::cam::uin/100000000001:uin/100000000011
    Here, 100000000001 is a root account, while 100000000011 is a sub-account
    String Yes
    - - action List of related actions subject to the policy. Wildcard * is supported StringArray Yes
    - - - resource List of resource identification strings.
    Format: qcs::cos:<Region>:uid/<AppId>:<ShortBucketName>/*.
    Example: qcs::cos:ap-beijing:uid/1250000000:examplebucket/*
    StringArray
    - - condition Constraints, can be left blank. For details, see Element Reference String No

    Callback function description

    },function (err,data) {
    Parameter Name Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object

    Querying bucket policies

    Feature description

    This API is used to query the permission policies of a specified bucket.

    Use case

    cos.getBucketPolicy({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
    },function (err,data) {
        console.log(err || data);
    });

    Sample response

    {
        "Policy": {
            "version": "2.0",
            "Statement": [{
                "Action": [
                    "name/cos:PutObject",
                    "name/cos:InitiateMultipartUpload",
                    "name/cos:ListMultipartUploads",
                    "name/cos:ListParts",
                    "name/cos:UploadPart",
                    "name/cos:CompleteMultipartUpload"
                ],
                "Effect": "allow",
                "Principal": {
                    "qcs": ["qcs::cam::uin/100000000001:uin/100000000001"]
                },
                "Resource": ["qcs::cos:ap-beijing:uid/1250000000:examplebucket-1250000000/*"],
                "Sid": "costs-1539833197000000307620-46518-39"
            }]
        },
        "statusCode": 200,
        "headers": {}
    }

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes

    Callback function description

    },function (err,data) {
    Parameter Name             Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - Policy Permission policy. For more information, see Cloud Access Management Practices > Policy Syntax Object
    - - version Version number, fixed as 2.0 String
    - - statement List of permission policy statements ObjectArray
    - - - effect Effect; enumerated values: allow, deny String
    - - - principal Identity information ObjectArray
    - - - - qcs ID string.
    Format: qcs::cam::uin/100000000001:uin/100000000011.
    100000000001 is a root account, while 100000000011 is a sub-account
    String
    - - - action List of related actions subject to the policy. Wildcard * is supported StringArray
    - - - resource List of resource identification strings.
    Format: qcs::cos:<Region>:uid/<AppId>:<ShortBucketName>/*.
    Example: qcs::cos:ap-beijing:uid/1250000000:examplebucket/*
    StringArray
    - - condition Constraints, can be left blank. For details, see Element Reference ObjectArray

    Deleting bucket policies

    Feature description

    This API is used to delete the permission policy of a specified bucket.

    Note:

    Only the Bucket owner is allowed to initiate this request. You will receive a 204 No Content error if the permission policy does not exist.

    Use case

    cos.deleteBucketPolicy({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
    },function (err,data) {
        console.log(err || data);
    });

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes

    Callback function description

    },function (err,data) {
    Parameter Name             Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object

    Tag management

    Setting bucket tags

    Feature description

    This API is used to set tags for an existing bucket.

    Use case

    cos.putBucketTagging({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
        Tagging: {
            "Tags": [
                {"Key": "k1", "Value": "v1"},
                {"Key": "k2", "Value": "v2"}
            ]
        }
    },function (err,data) {
        console.log(err || data);
    });

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes
    Tagging Tag information Object Yes
    - Tags Tag information ObjectArray Yes
    - - Key Tag name String Yes
    - - Value Tag value String Yes

    Callback function description

    },function (err,data) {
    Paramter Name         Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object

    Querying bucket tags

    Feature description

    This API is used to query the existing tags of a specified bucket.

    Use case

    cos.getBucketTagging({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
    },function (err,data) {
        console.log(err || data);
    });

    Sample response

    {
        "Tags": [
            {"Key": "k1", "Value": "v1"},
            {"Key": "k2", "Value": "v2"}
        ],
        "statusCode": 200,
        "headers": {}
    }

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes

    Callback function description

    },function (err,data) {
    Parameter Name             Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    - Tags Tag information ObjectArray
    - - Key Tag name String
    - - Value Tag value String

    Deleting bucket tags

    Feature description

    This API is used to delete specified bucket tags.

    Use case

    cos.deleteBucketTagging({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
    },function (err,data) {
        console.log(err || data);
    });

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes

    Callback function description

    },function (err,data) {
    Parameter Name Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object

    Versioning

    Setting versioning

    Feature description

    This API is used to enable or suspend versioning for a bucket.

    1. If you have never enabled versioning for the bucket, GET Bucket versioning will not return a versioning status.
    2. Once enabled, versioning can be suspended but not disabled.
    3. Set the versioning status value to Enabled or Suspended to enable or suspend versioning, respectively.
    4. To set versioning for a bucket, you need to have write permission for the bucket.

    Use case

    cos.putBucketVersioning({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
        VersioningConfiguration: {
            Status: "Enabled"
        }
    },function (err,data) {
        console.log(err || data);
    });

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes
    VersioningConfiguration Defines the versioning configuration information of the bucket Object Yes
    - Status Versioning status; enumerated values: Enabled, Suspended String No

    Callback function description

    },function (err,data) {
    Parameter Name             Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object

    Querying versioning

    Feature description

    This API is used to query the versioning configuration of a bucket.

    Use case

    cos.getBucketVersioning({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
    },function (err,data) {
        console.log(err || data);
    });

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes

    Callback function description

    },function (err,data) {
    Parameter Name                                  Parameter Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 4044 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    - VersioningConfiguration Versioning configuration of the bucket Object
    - - Status Versioning status; enumerated values: Enabled, Suspended String

    Cross-region replication

    Setting cross-region replication

    Feature description

    This API is used to set the cross-region replication rules for a bucket.

    Buckets must have versioning enabled to use cross-region replication.

    Use case

    cos.putBucketReplication({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
        ReplicationConfiguration: { /*Required*/
            Role: "qcs::cam::uin/100000000001:uin/100000000001",
            Rules: [{
                ID: "1",
                Status: "Enabled",
                Prefix: "sync/",
                Destination: {
                    Bucket: "qcs::cos:ap-beijing::destinationbucket-1250000000",
                    StorageClass: "Standard",
                }
            }]
        }
    },function (err,data) {
        console.log(err || data);
    });

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes
    ReplicationConfiguration Defines cross-region replication rules Object Yes
    - Role The role used in the replication process.
    Format: qcs::cam::uin/100000000001:uin/100000000011.
    100000000001 is a root account, while 100000000011 is a sub-account
    Object No
    - Rules List of specific replication rules ObjectArray Yes
    - - ID Identifies the ID of a specific rule String No
    - - Status Identifies whether a rule is in effect. Enumerated values: Enabled, Disabled String Yes
    - - Prefix Prefix match policy (blank for root directory). Prefixes cannot overlap; otherwise, an error is returned. String No
    - - Destination Destination bucket information Object Yes
    - - - Bucket Destination bucket name.
    Format: qcs:id/0:cos:<Region>:appid/<AppId>:<ShortBucketName>
    Example: qcs:id/0:cos:ap-chengdu:appid/1250000000:backup
    Object Yes
    - - - StorageClass Storage class after the replication; enumerated values: STANDARD, STANDARD_IA. Default value: STANDARD Object No

    Callback function description

    },function (err,data) {
    Parameter Name             Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object

    Querying cross-region replication

    Feature description

    This API is used to query the cross-region replication rules of a specified bucket.

    Use case

    cos.getBucketReplication({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
    },function (err,data) {
        console.log(err || data);
    });

    Sample response

    {
        "ReplicationConfiguration": {
            "Role": "qcs::cam::uin/100000000001:uin/100000000001",
            "Rules": {
                "ID": "1",
                Status: "Enabled",
                "Prefix": "sync/",
                "Destination": {
                    "Bucket": "qcs:id/0:cos:ap-chengdu:appid/1250000000:backup",
                    "StorageClass": "Standard"
                }
            }
        },
        "statusCode": 200,
        "headers": {}
    }

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes

    Callback function description

    },function (err,data) {
    Parameter Name                                  Parameter Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - ReplicationConfiguration Cross-region replication rule Object
    - - Role The role used in the replication process.
    Format: qcs::cam::uin/100000000001:uin/100000000011.
    100000000001 is a root account, while 100000000011 is a sub-account
    Object
    - - Rules List of specific replication rules ObjectArray
    - - - ID Identifies the ID of a specific rule String
    - - - Status Identifies whether the rule takes effect. Enumerated values: Enabled, Disabled String
    - - - Prefix Prefix match policy (blank for root directory). Prefixes cannot overlap; otherwise, an error is returned. String
    - - - Destination Destination bucket information Object
    - - - Bucket Destination bucket name.
    Format: qcs:id/0:cos:<Region>:appid/<AppId>:<ShortBucketName>.
    Example: qcs:id/0:cos:ap-chengdu:appid/1250000000:backup
    Object
    - - - - StorageClass Storage class after the replication; enumerated values: STANDARD, STANDARD_IA. Default value: STANDARD Object

    Deleting cross-region replication

    Feature description

    This API is used to delete the cross-region replication rules of a bucket.

    Use case

    cos.deleteBucketReplication({
        Bucket: 'examplebucket-1250000000', /*Required*/
        Region: 'COS_REGION',     /* Bucket region. Required */
    },function (err,data) {
        console.log(err || data);
    });

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, see Regions and Access Domain Names String Yes

    Callback function description

    },function (err,data) {
    Parameter Name             Description Type
    err Object returned when an error (network error or service error) occurs. If the request is successful, this is null. For more information, see Error Codes Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object
    data Object returned when the request is successful. If the request fails, this is null Object
    - statusCode HTTP status code returned by the request, such as 200, 403, and 404 Number
    - headers Header information returned by the request Object

    Was this page helpful?

    Was this page helpful?

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