Bucket Management

Last updated: 2020-05-20 14:57:28

    Overview

    This document provides an overview of APIs and SDK code samples related to cross-origin access, lifecycle, 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

    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

    Feature description

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

    Method prototype

    put_bucket_cors(Bucket, CORSConfiguration={}, **kwargs)

    Sample request

    response = client.put_bucket_cors(
        Bucket='examplebucket-1250000000',
        CORSConfiguration={
            'CORSRule': [
                {
                    'ID': 'string',
                    'MaxAgeSeconds': 100,
                    'AllowedOrigin': [
                        'string',
                    ],
                    'AllowedMethod': [
                        'string',
                    ],
                    'AllowedHeader': [
                        'string',
                    ],
                    'ExposeHeader': [
                        'string',
                    ]
                }
            ]
        },
    )

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    CORSRule Sets the appropriate cross-origin access rules, including ID, MaxAgeSeconds, AllowedOrigin, AllowedMethod, AllowedHeader, and ExposeHeader List Yes
    ID Set rule ID String No
    MaxAgeSeconds Sets the validity period of the results obtained by OPTIONS int No
    AllowedOrigin Sets allowed access sources, e.g. "http://cloud.tencent.com". The wildcard "*" is supported. Dict Yes
    AllowedMethod Sets allowed methods, including GET, PUT, HEAD, POST, DELETE Dict Yes
    AllowedHeader Sets the custom HTTP request headers that are allowed to be used by requests. The wildcard "*" is supported. Dict No
    ExposeHeader Configures the custom header information that can be received by the browser from the server end. Dict No

    Response description

    This method returns None.

    Querying cross-origin access configuration

    Feature description

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

    Method prototype

    get_bucket_cors(Bucket, **kwargs)

    Sample request

    response = client.get_bucket_cors(
        Bucket='examplebucket-1250000000',
    )

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes

    Response description

    Bucket cross-origin access configuration in dict format

    {
        'CORSRule': [
            {
                'ID': 'string',
                'MaxAgeSeconds': 100,
                'AllowedOrigin': [
                    'string',
                ],
                'AllowedMethod': [
                    'string',
                ],
                'AllowedHeader': [
                    'string',
                ],
                'ExposeHeader': [
                    'string',
                ],
            }
        ]
    }
    Parameter Name Description Type
    CORSRule Cross-origin access rules, including ID, MaxAgeSeconds, AllowedOrigin, AllowedMethod, AllowedHeader, and ExposeHeader List
    ID Rule ID String
    MaxAgeSeconds Sets the validity period of the OPTIONS request result String
    AllowedOrigin Allowed access sources, e.g. "http://cloud.tencent.com". The wildcard "*" is supported. Dict
    AllowedMethod Allowed methods, including GET, PUT, HEAD, POST, DELETE Dict
    AllowedHeader The custom HTTP request headers that are allowed to be used by requests. The wildcard "*" is supported. Dict
    ExposeHeader The custom header information that can be received by the browser from the server end. Dict

    Deleting cross-origin configuration

    Feature description

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

    Method prototype

    delete_bucket_cors(Bucket, **kwargs)

    Sample request

    response = client.delete_bucket_cors(
        Bucket='examplebucket-1250000000',
    )

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes

    Response description

    This method returns None.

    Lifecycle

    Setting a lifecycle configuration

    Feature description

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

    Method prototype

    put_bucket_lifecycle(Bucket, LifecycleConfiguration={}, **kwargs)

    Sample request

    from qcloud_cos import get_date
    response = client.put_bucket_lifecycle(
        Bucket='examplebucket-1250000000',
        LifecycleConfiguration={
            'Rule': [
                {
                    'ID': 'string',
                    'Filter': {
                        'Prefix': 'string',
                        'Tag': [
                            {
                                'Key': 'string',
                                'Value': 'string'
                            }
                        ]
                    },
                    'Status': 'Enabled'|'Disabled',
                    'Expiration': {
                        'Days': 100,
                        'Date': get_date(2018, 4, 20)
                    },
                    'Transition': [
                        {
                            'Days': 100,
                            'Date': get_date(2018, 4, 20),
                            'StorageClass': 'Standard_IA'|'Archive'
                        },
                    ],
                    'NoncurrentVersionExpiration': {
                        'NoncurrentDays': 100
                    },
                    'NoncurrentVersionTransition': [
                        {
                            'NoncurrentDays': 100,
                            'StorageClass': 'Standard_IA'
                        },
                    ],
                    'AbortIncompleteMultipartUpload': {
                        'DaysAfterInitiation': 100
                    }
                }
            ]   
        }
    )

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Rule Sets the corresponding rules, including ID, Filter, Status, Expiration, Transition, NoncurrentVersionExpiration, NoncurrentVersionTransition, AbortIncompleteMultipartUpload List Yes
    ID Sets rule ID. string No
    Filter Describes a collection of objects that are subject to the rules. To set rules for all objects in the bucket, leave Prefix empty. Dict Yes
    Status Sets whether Rule is enabled. Available values: Enabled, Disabled Dict Yes
    Expiration Sets the expiration rule for an object. You can specify an expiry date (Date) or the number of days before the objects expire (Days). The format of Date must be GMT ISO 8601. You can specify the date using the get_date method. Dict No
    Transition Sets the rule for when an object transitions to a specified storage class. You can specify the number of days (Days) or a specified date (Date). The format of Date must be GMT ISO 8601. You can specify the date using get_date method. Available values for StorageClass: Standard_IA and Archive. Multiple rules can be set at a time. List No
    NoncurrentVersionExpiration Sets the expiration rule for noncurrent object versions. You can specify the number of days before the object expires (NoncurrentDays). Dict No
    NoncurrentVersionTransition Sets the transition rule that describes when noncurrent objects transition to another storage class. You can specify the number of days (NoncurrentDays). Valid values for StorageClass: Standard_IA. Multiple rules can be set at a time. List No
    AbortIncompleteMultipartUpload Indicates the number of days within which the upload must be completed after the multipart upload starts. Dict No

    Response description

    This method returns None.

    Querying a lifecycle configuration

    Feature description

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

    Sample request

    response = client.get_bucket_lifecycle(
        Bucket='examplebucket-1250000000',
    )

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes

    Response description

    Bucket lifecycle configuration in dict format

    {
        'Rule': [
            {
                'ID': 'string',
                'Filter': {
                    'Prefix': 'string',
                    'Tag': [
                            {
                                'Key': 'string',
                                'Value': 'string'
                            }
                    ]
                },
                'Status': 'string',
                'Expiration': {
                    'Days': 100,
                    'Date': 'string'
                },
                'Transition': [
                    {
                        'Days': 100,
                        'Date': 'string',
                        'StorageClass': 'STANDARD_IA'|'Archive'
                    },
                ],
                'NoncurrentVersionExpiration': {
                    'NoncurrentDays': 100
                },
                'NoncurrentVersionTransition': [
                    {
                        'NoncurrentDays': 100,
                        'StorageClass': 'STANDARD_IA'
                    },
                ],
                'AbortIncompleteMultipartUpload': {
                    'DaysAfterInitiation': 100
                }
            }
        ]   
    }
    Parameter Name Description Type
    Rule Corresponding rules, including ID, Filter, Status, Expiration, Transition, NoncurrentVersionExpiration, NoncurrentVersionTransition, AbortIncompleteMultipartUpload List
    ID Rule ID String
    Filter Describes a collection of objects that are subject to the rules. Dict
    Status Sets whether Rule is enabled. Valid values: Enabled, Disabled Dict
    Expiration Sets the expiration rule for an object. You can specify an expiry date (Date) or the number of days before the object expires (Days). Dict
    Transition Rule for when an object transitions to a specified storage class. You can specify the number of days (Days) or the specified date (Date). Available values for StorageClass: Standard_IA, Archive. List
    NoncurrentVersionExpiration Sets the expiration rule for noncurrent object versions. You can specify the number of days before the object expires (NoncurrentDays). Dict
    NoncurrentVersionTransition Transition rule that describes when noncurrent objects transition to another storage class. You can specify the number of days (NoncurrentDays). Available values for StorageClass: Standard_IA. List
    AbortIncompleteMultipartUpload Number of days within which the upload must be completed after the multipart upload starts. Dict

    Deleting a lifecycle configuration

    Feature description

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

    Method prototype

    delete_bucket_lifecycle(Bucket, **kwargs)

    Sample request

    response = client.delete_bucket_lifecycle(
        Bucket='examplebucket-1250000000',
    )

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes

    Response description

    This method returns None.

    Versioning

    Setting versioning

    Feature description

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

    Method prototype

    put_bucket_versioning(Bucket, Status, **kwargs)

    Sample request

    Enabling versioning
    response = client.put_bucket_versioning(
        Bucket='examplebucket-1250000000',
        Status='Enabled'
    )

    Suspend Versioning
    response = client.put_bucket_versioning(
        Bucket='examplebucket-1250000000',
        Status='Suspended'
    )

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Status Sets versioning status. Valid values: Suspended, Enabled String Yes

    Response description

    This method returns None.

    Querying versioning

    Feature description

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

    Method prototype

    get_bucket_versioning(Bucket, **kwargs)

    Sample request

    response = client.get_bucket_versioning(
        Bucket='examplebucket-1250000000',
    )

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes

    Response description

    Bucket versioning configuration in dict format

    {
        'Status': 'Enabled'|'Suspended'
    }
    Parameter Name Description Type
    Status Versioning status. Valid values: Suspended, Enabled String

    Cross-region replication

    Setting cross-region replication

    Feature description

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

    Method prototype

    put_bucket_replication(Bucket, ReplicationConfiguration={}, **kwargs)

    Sample request

    response = client.put_bucket_replication(
        Bucket='examplebucket-1250000000',
        ReplicationConfiguration={
            'Role': 'qcs::cam::uin/100000000001:uin/100000000001',
            'Rule': [
                {
                    'ID': 'string',
                    'Status': 'Enabled'|'Disabled',
                    'Prefix': 'string',
                    'Destination': {
                        'Bucket': 'qcs::cos:ap-beijing::destinationbucket-1250000000',
                        'StorageClass': 'STANDARD'|'STANDARD_IA'
                    }
                },
                {
                    'ID': 'string',
                    'Status': 'Enabled'|'Disabled',
                    'Prefix': 'string',
                    'Destination': {
                        'Bucket': 'qcs::cos:ap-beijing::destinationbucket2-1250000000',
                        'StorageClass': 'STANDARD'|'STANDARD_IA'
                    }
                },
            ]   
        }
    )

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes
    Role Replication initiator identifier: qcs::cam::uin/<OwnerUin>:uin/<SubUin> string No
    Rule Sets rule ID,Status,Prefix,and Destination List Yes
    ID Sets rule ID. string No
    Status Sets whether Rule is enabled. Valid values: Enabled, Disabled String Yes
    Prefix Prefix used to filter objects that are subject to the rule. If it is left empty, it means that the rule applies to all objects in the bucket String Yes
    Destination Describes information on object copies, including Bucket and StorageClass Dict Yes
    Bucket Sets the destination bucket of the cross-region replication. Format: qcs::cos:[region]::[BucketName-APPID] String Yes
    StorageClass Sets the storage class of the object copies. Valid values: STANDARD, STANDARD_IA String No

    Response description

    This method returns None.

    Querying cross-region replication

    Feature description

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

    Method prototype

    get_bucket_replication(Bucket, **kwargs)

    Sample request

    response = client.get_bucket_replication(
        Bucket='examplebucket-1250000000'
    )

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes

    Response description

    Bucket cross-region replication configuration in dict format

    {
        'Role': 'qcs::cam::uin/100000000001:uin/100000000001',
        'Rule': [
            {
                'ID': 'string',
                'Status': 'Enabled'|'Disabled',
                'Prefix': 'string',
                'Destination': {
                    'Bucket': 'qcs::cos:ap-beijing::destinationbucket-1250000000',
                    'StorageClass': 'STANDARD'|'STANDARD_IA'
                }
            },
            {
                'ID': 'string',
                'Status': 'Enabled'|'Disabled',
                'Prefix': 'string',
                'Destination': {
                    'Bucket': 'qcs::cos:ap-beijing::destinationbucket2-1250000000',
                    'StorageClass': 'STANDARD'|'STANDARD_IA'
                }
            },
        ]  
    }
    Parameter Name Description Type
    Role Replication initiator identifier: qcs::cam::uin/<OwnerUin>:uin/<SubUin> string
    Rule Sets rules for cross-region replication, including rule ID, Status, Prefix, and Destination List
    ID Cross-region replication rule ID String
    Status Sets whether Rule is enabled. Valid values: Enabled, Disabled String
    Prefix Prefix used to filter objects that are subject to the rule. If it is left empty, it means that the rule applies to all objects in the bucket String
    Destination Describes information on object copies, including Bucket and StorageClass Dict
    Bucket Sets the destination bucket of the cross-region replication. Format: qcs::cos:[region]::[BucketName-APPID] String
    StorageClass Sets the storage class of the object copies. Valid values: STANDARD, STANDARD_IA String

    Deleting cross-region replication

    Feature description

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

    Method prototype

    delete_bucket_replication(Bucket, **kwargs)

    Sample request

    response = client.delete_bucket_replication(
        Bucket='examplebucket-1250000000',
    )

    Parameter description

    Parameter Name Description Type Required
    Bucket Bucket name in the format: BucketName-APPID String Yes

    Response description

    This method returns None.

    Was this page helpful?

    Was this page helpful?

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