tencent cloud

Feedback

PUT Bucket ObjectLockConfiguration

Last updated: 2024-03-28 18:12:17

    Function Description

    COS supports the enabling of the object lock function for storage buckets, and allows the configuration of corresponding default retention period. The PUT Bucket ObjectLockConfiguration interface supports the following functions:
    1. You can enable the object lock function for a storage bucket. This indicates that the object lock function can be used in the storage bucket. Users can add locks to the objects in the storage bucket based on their requirements. For details about how to add locks after the upload process, see PUT Object Retention. For details about how to add locks during the upload process, refer to PUT Object.
    Note:
    Once the object lock function of a storage bucket is enabled, it cannot be disabled.
    2. After the object lock function is enabled, you can configure a default retention period for the storage bucket. If the object uploaded by the user does not carry an object lock header, the retention period will be automatically set based on the default retention period. For details, refer to Object Lock Overview.
    Note:
    The default retention period is an optional configuration, which can be modified or disabled.
    Modifying the default retention period will not affect the lock status of existing objects. It only affects subsequently added objects.

    Request

    Request Example

    PUT /?object-lock HTTP/1.1
    Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
    Date: GMT Date
    Authorization: Auth String
    Note:
    Host: <BucketName-APPID>.cos.<Region>.myqcloud.com. <BucketName-APPID> indicates the storage bucket name suffixed with APPID, for instance, examplebucket-1250000000. For details, refer to Bucket Overview > Basic Information and Bucket Overview > Bucket Naming Conventions. <Region> indicates the available region for COS. For more information, refer to Regions and Access Endpoints.
    Authorization: Auth String (for details, refer to Request Signature).

    Request Headers

    This interface only uses common request headers. For details, refer to Common Request Headers.

    Request Body

    <ObjectLockConfiguration>
    <ObjectLockEnabled>Enabled</ObjectLockEnabled>
    <Rule>
    <DefaultRetention>
    <Mode>COMPLIANCE</Mode>
    <Days>30</Days>
    </DefaultRetention>
    </Rule>
    </ObjectLockConfiguration>
    The specific data is described as follows:
    Node Name (Keyword)
    Parent Node
    Description
    Type
    Mandatory
    ObjectLockConfiguration
    None
    Object lock configuration.
    Container
    Yes
    ObjectLockEnabled
    ObjectLockConfiguration
    Whether to enable the object lock function. Only Enabled is supported for input. Once the object lock function is enabled, it cannot be disabled.
    String
    Yes
    Rule
    ObjectLockConfiguration
    Object lock rules.
    Container
    No
    DefaultRetention
    ObjectLockConfiguration.Rule
    Default retention period and mode of the object lock function for a storage bucket. For an object that does not carry a lock header, the retention period should be set in accordance with the bucket configuration. The configuration of the storage bucket supports deletion and modification.
    Container
    Yes
    Days
    ObjectLockConfiguration.Rule.DefaultRetention
    Default object lock period (range: 1-36500).
    Int
    Yes
    Mode
    ObjectLockConfiguration.Rule.DefaultRetention
    Default object lock mode. Only the enumerated value COMPLIANCE is supported. If this field remains unfilled, the default value will be COMPLIANCE.
    Enum
    No

    Response

    Response Headers

    This interface only returns common response headers. For more details, refer to Common Response Headers.

    Response Body

    The response body is empty.

    Error Codes

    This interface adheres to unified error responses and error codes. Refer to Error Codes.

    Examples

    Example 1: Enabling the Object Lock Function for a Storage Bucket

    Request

    The following example demonstrates enabling the object lock function for the storage bucket named examplebucket-1250000000.
    PUT /?object-lock HTTP/1.1
    Host: exmaplebucket-1250000000.cos.ap-beijing.myqcloud.com
    Content-Length: 281
    Content-Type: application/x-www-form-urlencoded
    Authorization: Auth String
    
    
    <ObjectLockConfiguration>
    <ObjectLockEnabled>Enabled</ObjectLockEnabled>
    </ObjectLockConfiguration>

    Response

    HTTP/1.1 200 OK
    Content-Length: 0
    Connection: keep-alive
    Date: Fri, 09 Dec 2022 08:17:20 GMT
    Server: tencent-cos
    x-cos-request-id: NjM5MmVmMTBfNmM0ZTQ0MGJfMjA4****

    Example 2: Enabling the Object Lock Function for a Storage Bucket and Configuring the Default Retention Period

    Request

    The following example illustrates the enabling of the object lock function for the storage bucket named examplebucket-1250000000, along with the configuration of the default retention period.
    PUT /?object-lock HTTP/1.1
    Host: exmaplebucket-1250000000.cos.ap-beijing.myqcloud.com
    Content-Length: 281
    Content-Type: application/x-www-form-urlencoded
    Authorization: Auth String
    
    <ObjectLockConfiguration>
    <ObjectLockEnabled>Enabled</ObjectLockEnabled>
    <Rule>
    <DefaultRetention>
    <Days>1</Days>
    <Mode>COMPLIANCE</Mode>
    </DefaultRetention>
    </Rule>
    </ObjectLockConfiguration>

    Response

    HTTP/1.1 200 OK
    Content-Length: 0
    Connection: keep-alive
    Date: Fri, 09 Dec 2022 08:17:20 GMT
    Server: tencent-cos
    x-cos-request-id: NjM5MmVmMTBfNmM0ZTQ0MGJfMjA4****

    Example 3: Modifying the Default Retention Period of a Storage Bucket

    Request

    The following example illustrates the modification of the default retention period for the storage bucket named examplebucket-1250000000. For instance, if the previous default retention period was 3 days, the subsequent request will amend it to 10 days.
    PUT /?object-lock HTTP/1.1
    Host: exmaplebucket-1250000000.cos.ap-beijing.myqcloud.com
    Content-Length: 281
    Content-Type: application/x-www-form-urlencoded
    Authorization: Auth String
    
    <ObjectLockConfiguration>
    <ObjectLockEnabled>Enabled</ObjectLockEnabled>
    <Rule>
    <DefaultRetention>
    <Days>10</Days>
    <Mode>COMPLIANCE</Mode>
    </DefaultRetention>
    </Rule>
    </ObjectLockConfiguration>

    Response

    HTTP/1.1 200 OK
    Content-Length: 0
    Connection: keep-alive
    Date: Fri, 09 Dec 2022 08:17:20 GMT
    Server: tencent-cos
    x-cos-request-id: NjM5MmVmMTBfNmM0ZTQ0MGJfMjA4****