Bucket Management

Last updated: 2020-04-29 11:44:08

PDF

Introduction

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 cross-origin access permissions for 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 information of a bucket

Lifecycle

API Operation Description
PUT Bucket lifecycle Setting lifecycle Sets lifecycle management for 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 the specified bucket
GET Bucket policy Querying bucket policy Queries the permission policy of the specified bucket
DELETE Bucket policy Deleting a bucket policy Deletes the permission policy of the 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 versioning configuration for 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 cross-region replication rules for 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. If you want to modify cross-domain access configuration on the front end, the bucket needs to support cross-domain acces. You can configure cross-domain access on the console. For details, see [Getting Started].
  2. Make sure changing cross-origin access configuration does not affect cross-origin requests under the current origin.

Feature

This API (PUT Bucket cors) is used to configure the cross-origin resource sharing (CORS) permission of a bucket. You can make 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..

Samples

cos.putBucketCors({
    Bucket: 'examplebucket-1250000000', /*Required*/
    Region: 'COS_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 of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region and Domain Name Access String Yes
CORSRules List of all the information on CORS configuration ObjectArray No
- - ID Configures the rule ID String
- AllowedMethods Allowed HTTP operations. Enumerated values: GET, PUT, HEAD, POST, DELETE StringArray Yes
- - AllowedOrigins Allowed origin in the format of 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 succeeds. 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-origin access configuration

Feature

This API (GET Bucket cors) 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.

Samples

cos.getBucketCors({
    Bucket: 'examplebucket-1250000000', /*Required*/
    Region: 'COS_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 of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region and Domain Name Access String Yes

Callback Function Description

function(err, data) { ... }
Parameter Name                                       Paramater 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 succeeds. 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 cross-origin configuration

Feature

This API (DELETE Bucket cors) is used to delete the cross-origin access configuration of a bucket.

  1. If you delete the cross-origin access configuration of the current bucket, all cross-origin access requests will fail. Please proceed with caution.
  2. We do not recommended you use this method in a browser.

Samples

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

Parameter Description

Parameter Name Description Type Required
Bucket Bucket name in the format of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region and Domain Name Access 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 succeeds. 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 the lifecycle

Feature

This API (PUT Bucket lifecycle) is used to set the lifecycle management configuration for a bucket.

Samples

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

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

Example 3: Clean up the delate marker of expired files 180 days after the upload.

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

Sample 4. Delete parts 30 days after upload

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

Example 5: Deposit the historical version in archive storage 30 days after it is generated.

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

Parameter Description

Parameter Name                                                 Parameter Description Type Required
Bucket Bucket name in the format of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region and Domain Name Access String Yes
- Rules List of specific replication 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 by 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 the action corresponding to the rule will be executed after the last modification date of the object. The valid value of this field is a non-negative integer, and a maximum of 3650 days is supported Number Yes
StorageClass Sets the object storage class; enumerated values: STANDARD, STANDARD_IA, ARCHIVE. Default value: STANDARD String No
- NoncurrentVersionTransition Specifies historical version object conversion attributes ObjectArray No
- - NoncurrentDays Indicates the historical version object is converted after the number of effective days determined by this value Number Yes
- StorageClass Object storage class; enumerated values: STANDARD, STANDARD_IA, ARCHIVE String
- Expiration Rule expiration attributes Object No
- - ExpiredObjectDeleteMarker Deletes expired delete marker of the object, enumerated values are true and false, cannot coexist with Days Boolean Yes
- - Days Specifies the number of days after the last modification date of the object for the action corresponding to the rule to be deleted, cannot coexist with ExpiredObjectDeleteMarker Number Yes
- - AbortIncompleteMultipartUpload Indicates to delete the parts Object No
- - DaysAfterInitiation Parts are deleted after the number of effective days determined by this value, starting from the file upload time 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 succeeds. 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 the lifecycle

Feature

This API (GET Bucket lifecycle) is used to query the lifecycle management configuration of a bucket.

Samples

cos.getBucketLifecycle({
    Bucket: 'examplebucket-1250000000', /*Required*/
    Region: 'COS_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 of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region and Domain Name Access 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 succeeds. 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 replication 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 the last modification date of the object the action corresponding to the rule will be executed. The valid value of this field is a non-negative integer, and a maximum of 3650 days is supported
- StorageClass Object storage class; enumerated values: STANDARD, STANDARD_IA, ARCHIVE String
- - NoncurrentVersionTransition Specifies historical version object conversion attributes ObjectArray
- - - NoncurrentDays Indicates the historical version object is converted after the number of effective days determined by the value Number
- StorageClass Object storage class; enumerated values: STANDARD, STANDARD_IA, ARCHIVE String
- - Expiration Rule expiration attributes Object
- - - ExpiredObjectDeleteMarker Deletes the delete marker of the expired object, emenumerated values are true and false, cannot coexist with Days Boolean
- - - Days Specifies the number of days after the last modification date of the object for the action corresponding to the rule to be deleted. It cannot coexist with ExpiredObjectDeleteMarker Number
- - AbortIncompleteMultipartUpload Indicates to delete the parts Object
- - - DaysAfterInitiation Parts are deleted after the number of effective days determined by this value, starting from the file upload time and must be a positive integer Number

Deleting the lifecycle

Feature

This API (GET Bucket lifecycle) is used to query the lifecycle management configuration of a bucket.

Samples

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

Parameter Description

Parameter Name Description Type Required
Bucket Bucket name in the format of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region and Domain Name Access 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 succeeds. 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

This API (PUT Bucket policy) is used to set permission policies for a specified bucket.

Samples

cos.putBucketPolicy({
    Bucket: 'examplebucket-1250000000', /*Required*/
    Region: 'COS_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 of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region and Domain Name Access String Yes
Policy Permission policy. For more information, see Access Management 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 Yes
- - condition Constraints, can be left blank. For details, see Condition 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 succeeds. 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

This API (GET Bucket policy) is used to query the permission policies of a specified bucket.

Samples

cos.getBucketPolicy({
    Bucket: 'examplebucket-1250000000', /*Required*/
    Region: 'COS_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-guangzhou: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 of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region 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
data Object returned when the request succeeds. 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/&ltAppId>:<ShortBucketName>/*.
Example: qcs::cos:ap-beijing:uid/1250000000:examplebucket/*
StringArray
- - condition Constraints, can be left blank. For details, see Condition ObjectArray

Deleting bucket policies

Feature

This API (DELETE Bucket policy) is used to delete the permission policy of the specified bucket.

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

Samples

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

Parameter Description

Parameter Name Description Type Required
Bucket Bucket name in the format of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region and Domain Name Access 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 succeeds. 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

This API (PUT Bucket tagging) is used to set tags for an existing bucket.

Samples

cos.putBucketTagging({
    Bucket: 'examplebucket-1250000000', /*Required*/
    Region: 'COS_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 of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region and Domain Name Access 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) { ... }
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 succeeds. 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

This API (GET Bucket tagging) is used to query the existing tags of a specified bucket.

Samples

cos.getBucketTagging({
    Bucket: 'examplebucket-1250000000', /*Required*/
    Region: 'COS_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 of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region 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 succeeds. 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

This API (DELETE Bucket tagging) is used to delete specified bucket tags.

Samples

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

Parameter Description

Parameter Name Description Type Required
Bucket Bucket name in the format of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region and Domain Name Access 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 succeeds. 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

The PUT Bucket versioning API is used to enable or suspend versioning for a bucket.

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

Samples

cos.putBucketVersioning({
    Bucket: 'examplebucket-1250000000', /*Required*/
    Region: 'COS_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 of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region and Domain Name Access String Yes
VersioningConfiguration Defines the versioning configuration 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 succeeds. 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

This API (GET Bucket versioning) is used to query the versioning configuration of a bucket.

Samples

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

Parameter Description

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

Callback Function Description

function(err, data) { ... }
Parameter Name                                           Paramater 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 succeeds. 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

This API (PUT Bucket replication) is used to set cross-region replication rules for a bucket.

Buckets must have version control enabled to use cross-region replication.

Samples

cos.putBucketReplication({
    Bucket: 'examplebucket-1250000000', /*Required*/
    Region: 'COS_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 of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region and Domain Name Access 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 the rule takes effect. Enumerated values: Enabled, Disabled String Yes
prefix Prefix match policy (blank for root directory). Prefixes cannot overlap; otherwise, an error is returned NSString*
- - Destination Destination bucket information Object Yes
- - - Bucket Destination bucket for the replication.
Format: qcs::cos:<Region>:appid/<AppId>:<ShortBucketName>
Example: qcs::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 succeeds. 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

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

Samples

cos.getBucketReplication({
    Bucket: 'examplebucket-1250000000', /*Required*/
    Region: 'COS_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::cos:ap-chengdu:appid/1250000000:backup",
                "StorageClass": "Standard"
            }
        }
    },
    "statusCode": 200,
    "headers": {}
}

Parameter Description

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

Callback Function Description

function(err, data) { ... }
Parameter Name                                       Paramater 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 succeeds. 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. NSString*
- - - Destination Destination bucket information Object
- - - Bucket Destination bucket for the replication.
Format: qcs::cos:<Region>:appid/<AppId>:<ShortBucketName>.
Example: qcs::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

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

Samples

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

Parameter Description

Parameter Name Description Type Required
Bucket Bucket name in the format of BucketName-APPID String Yes
Region Bucket region. For enumerated values, see Region and Domain Name Access 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 succeeds. 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