PUT Bucket cors

Last updated: 2020-02-28 18:19:44

Description

API PUT Bucket cors is used to request the cross-domain resource sharing of Bucket, Permission. You can implement the configuration by passing a configuration file in XML format. The file size is limited to 64KB. By default, the Bucket holder directly has Permission to use the API, and the Bucket holder can also grant Permission to other users.

Request

Request Sample

PUT /?cors HTTP/1.1
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
Date: GMT Date
Content-Length: length
Content-Type: application/xml
Content-MD5: MD5
Authorization: Auth String

Note:

For more information on Authorization: Auth String (, please see Request Signature Documentation).

Request header

In addition to using common request headers, this API also supports the following required request headers. For more information on common request headers, please see Common Request Headers Document.

Name Description Type Required
Content-MD5 The Base64-encoded MD5 hash value of the request body content defined in RFC 1864, which is used for integrity checking to verify whether the request body has changed during transmission. String Yes

Request body

The request body of the request is a cross-domain rule.

<?xml version="1.0" encoding="UTF-8" ?>
<CORSConfiguration>
    <CORSRule>
        <ID>1234</ID>
        <AllowedOrigin>http://www.qq.com</AllowedOrigin>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedHeader>x-cos-meta-test</AllowedHeader>
        <MaxAgeSeconds>500</MaxAgeSeconds>
        <ExposeHeader>x-cos-meta-test1</ExposeHeader>
    </CORSRule>
</CORSConfiguration>

Below are the details:

Node name (keyword) Parent node Description Type Required
CORSConfiguration None Describes all the information about cross-domain resource sharing configuration, which can contain up to 100 CORSRule Container Yes

Content of Container node CORSConfiguration:

Node name (keyword) Parent node Description Type Required
CORSRule CORSConfiguration Describes all the information about cross-domain resource sharing configuration, which can contain up to 100 CORSRule Container Yes

Content of Container node CORSRule:

Node name (keyword) Parent node Description Type Required
Id CORSConfiguration.CORSRule Configure rule ID, but Optional String No
AllowedOrigin CORSConfiguration.CORSRule Allowed origin in the format of protocol://domain name[:port number], such as http://www.qq.com. Wildcard * is supported Strings Yes
AllowedMethod CORSConfiguration.CORSRule Allowed HTTP operations. Enumerated values: GET,PUT,HEAD,POST,DELETE Strings Yes
AllowedHeader CORSConfiguration.CORSRule When sending a OPTIONS request, tell the server which custom HTTP request headers can be used for subsequent requests, and wildcards are supported. * Strings Yes
MaxAgeSeconds CORSConfiguration.CORSRule Set the validity period of the result obtained by the OPTIONS request Integer Yes
ExposeHeader CORSConfiguration.CORSRule Set the custom header information that the browser can receive from the server Strings Yes

Response

Response header

This API only returns the public response header. For more information, please see Common Response Header Document.

Response body

The response body is empty.

Error Codes

Error Codes Description HTTP status code
SignatureDoesNotMatch The signature provided does not conform to the rules. The error code is returned. four hundred and three Forbidden
NoSuchBucket If the Bucket of the rule you are trying to add does not exist, return the error code four hundred and four Not Found

Actual case

Request

PUT /?cors HTTP/1.1
Host: examplebucket-1250000000.cos.ap-chengdu.myqcloud.com
Content-MD5: q+xJ56ypmuOSKbkohlpZIg==
Content-Type: application/xml
Authorization: q-sign-algorithm=sha1&q-ak=AKIDVMyLTL4B8rVt52LTozzPZBYffPs9****&q-sign-time=1578385303;1578392503&q-key-time=1578385303;1578392503&q-header-list=content-md5;content-type;host&q-url-param-list=cors&q-signature=730a82c7afed2a6c051870d54895193235e8****
Content-Length: 385

<?xml version="1.0" encoding="UTF-8" ?>
<CORSConfiguration>
    <CORSRule>
        <ID>1234</ID>
        <AllowedOrigin>http://www.qq.com</AllowedOrigin>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedHeader>x-cos-meta-test</AllowedHeader>
        <MaxAgeSeconds>500</MaxAgeSeconds>
        <ExposeHeader>x-cos-meta-test1</ExposeHeader>
    </CORSRule>
</CORSConfiguration>

Response

HTTP/1.1 200 OK
content-length: 0
connection: close
date: Tue, 07 Jan 2020 08:21:44 GMT
server: tencent-cos
x-cos-request-id: NWUxNDNmOThfNWFiMjU4NjRfMWIxYl9lYWY1****