Setting a Bucket Policy

Last Updated At: 2025-10-21 09:10:00

Description

The PUT Bucket policy API is used to write a permission policy for a bucket. The policy passed in this API will overwrite the existing one (if any) in the bucket.

Request

Request Example

PUT /?policy HTTP/1.1
Host: <BucketName-APPID>.<Endpoint>
Date: date
Content-Type:application/json
Content-MD5:MD5
Authorization: Auth String

Note:

Authorization: Auth String (See Request Signature for details.)

Request Header

Common Headers

This request uses common request headers. For details, see Public Request Headers.

Request Parameters

No special request parameters are included.

Request Body

For more information about the elements used in access policy settings, see Access Policy Language Overview.

{
    "Statement": [
        {
            "Principal": {
                "qcs": [
                    "qcs::cam::uin/${owner_uin}:uin/${sub_uin}"
                ]
            },
            "Effect": "${effect}",
            "Action": [
                "name/cos:${action}"
            ],
            "Resource": [
                "qcs::cos:${region}:uid/${appid}:${bucket}-${appid}/*"
            ]
        }
    ],
    "version": "2.0"
}

Response

Response Headers

Common Response Headers

This response uses common response headers. For details, see Common Response Headers.

Special Response Headers

This request has no special response header information.

Response Body

The response body is empty.

Error Code

No special error code is returned. For common error codes, see Error Codes.

Practical Case

Request

PUT /?policy HTTP/1.1
Host: <BucketName-APPID>.<Endpoint>
Authorization:q-sign-algorithm=sha1&q-ak=AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&q-sign-time=1484813288;32557709288&q-key-time=1484813288;32557709288&q-header-list=host&q-url-param-list=policy&q-signature=05f7fc936369f910a94a0c815e1f1752f034d47a
Content-Type: application/json
Content-Length: 233

{
  "Statement": [
    {
      "Principal": {
        "qcs": [
          "qcs::cam::uin/1250000000:uin/1250000000"
        ]
      },
      "Effect": "allow",
      "Action": [
        "name/cos:GetBucket"
      ],
      "Resource": [
        "qcs::cos:ap-city:uid/1250000000:examplebucket-1250000000/*"
      ]
    }
  ],
  "version": "2.0"
}

Response

HTTP/1.1 204 No Content
Content-Type: application/xml
Content-Length: 0
Connection: keep-alive
Date: Thu Jan 19 16:19:22 2017
x-cos-request-id: NTg4MDc2OGFfNDUyMDRlXzc3NTlfZTc4