forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Jawei, Li <lijiawei5@huawei.com> Co-committed-by: Jawei, Li <lijiawei5@huawei.com>
207 lines
18 KiB
HTML
207 lines
18 KiB
HTML
<a name="EN-US_TOPIC_0125560238"></a><a name="EN-US_TOPIC_0125560238"></a>
|
|
|
|
<h1 class="topictitle1">PUT Bucket CORS</h1>
|
|
<div id="body14744048"><p id="EN-US_TOPIC_0125560238__p15442113712815">You can use this operation to enable Cross-origin resource sharing (CORS) for specified buckets.</p>
|
|
<p id="EN-US_TOPIC_0125560238__p33894731">CORS is a standard mechanism proposed by the World Wide Web Consortium (W3C) that allows cross-origin requests from servers. For standard web page requests, the scripts and contents at one website cannot interact with those at another website due to the existence of the same origin policy (SOP).</p>
|
|
<p id="EN-US_TOPIC_0125560238__p36617123">OBS allows buckets to store static web resources. The buckets of OBS can serve as website resources if the buckets are properly used. For details, see section <a href="en-us_topic_0125560321.html">PUT Bucket website</a>. A website in OBS can respond to requests of another websites only after the CORS is properly configured.</p>
|
|
<p id="EN-US_TOPIC_0125560238__p61118651">Typical application scenarios are as follows:</p>
|
|
<ul id="EN-US_TOPIC_0125560238__ul13196948"><li id="EN-US_TOPIC_0125560238__li10993288">With the support of the CORS, you can use JavaScript and HTML 5 to construct web applications and directly access the resources in OBS without the need to use proxy servers for transfer.</li><li id="EN-US_TOPIC_0125560238__li31830735">You can enable the dragging function of HTML 5 to directly upload files to OBS (with the upload progress displayed) or update OBS contents using web applications.</li><li id="EN-US_TOPIC_0125560238__li18041159">You can host external web pages, style sheets, and HTML 5 applications in different domains. Web fonts or pictures on OBS can be shared by multiple websites.</li></ul>
|
|
<p id="EN-US_TOPIC_0125560238__p51663671">Only users granted the <strong id="EN-US_TOPIC_0125560238__b28152706">s3:PutBucketCORS</strong> permission can perform this operation. By default, only the bucket owner can perform this operation. The bucket owner can allow other users to perform this operation by granting them the permission. After the bucket CORS configuration is set, it will take effect within 2 minutes.</p>
|
|
<div class="section" id="EN-US_TOPIC_0125560238__section43823577"><h4 class="sectiontitle">Request Syntax</h4><pre class="screen" id="EN-US_TOPIC_0125560238__screen34493671121250">PUT /?cors HTTP/1.1
|
|
Host: bucketname.obs.example.com
|
|
User-Agent: agent
|
|
Accept: */*
|
|
Date: date
|
|
Authorization: authorization
|
|
Content-MD5: MD5
|
|
Content-Length: length
|
|
Expect: expect
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<CORSConfiguration>
|
|
<CORSRule>
|
|
<ID>id</ID>
|
|
<AllowedMethod>method</AllowedMethod>
|
|
<AllowedOrigin>origin</AllowedOrigin>
|
|
<AllowedHeader>header</AllowedHeader>
|
|
<MaxAgeSeconds>seconds</MaxAgeSeconds>
|
|
<ExposeHeader>header</ExposeHeader>
|
|
</CORSRule>
|
|
</CORSConfiguration></pre>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0125560238__section58867876"><h4 class="sectiontitle">Request Parameters</h4><p id="EN-US_TOPIC_0125560238__p50447774">This request involves no parameters.</p>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0125560238__section60048837"><h4 class="sectiontitle">Request Headers</h4><p id="EN-US_TOPIC_0125560238__p59737926"><a href="#EN-US_TOPIC_0125560238__table52047770">Table 1</a> lists the request header.</p>
|
|
|
|
<div class="tablenoborder"><a name="EN-US_TOPIC_0125560238__table52047770"></a><a name="table52047770"></a><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0125560238__table52047770" frame="border" border="1" rules="all"><caption><b>Table 1 </b>CORS request header</caption><thead align="left"><tr id="EN-US_TOPIC_0125560238__row62702560"><th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.9.3.2.4.1.1"><p id="EN-US_TOPIC_0125560238__p45742585">Header</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.9.3.2.4.1.2"><p id="EN-US_TOPIC_0125560238__p14161903">Description</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.9.3.2.4.1.3"><p id="EN-US_TOPIC_0125560238__p6263465">Remarks</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0125560238__row37578639"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.9.3.2.4.1.1 "><p id="EN-US_TOPIC_0125560238__p23970955">Content-MD5</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.9.3.2.4.1.2 "><p id="EN-US_TOPIC_0125560238__p62599170">The MD5 digest string of the message body is calculated according to the RFC 1864 standard. That is, calculate the 128-bit binary array (the message header data encrypted with MD5) first, and then use Base 64 encoding to convert the binary data to a character string.</p>
|
|
<p id="EN-US_TOPIC_0125560238__p26521624">Type: String</p>
|
|
<p id="EN-US_TOPIC_0125560238__p37368030">Example: n58IG6hfM7vqI4K0vnWpog==</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.9.3.2.4.1.3 "><p id="EN-US_TOPIC_0125560238__p6911623">Mandatory</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0125560238__row167671044112412"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.9.3.2.4.1.1 "><p id="EN-US_TOPIC_0125560238__p29431645102418">x-amz-security-token</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.9.3.2.4.1.2 "><p id="EN-US_TOPIC_0125560238__p1194320452248">Header field used to identify the request of a federated user. When the federal authentication function is enabled, users sending such requests are identified as federated users.</p>
|
|
<p id="EN-US_TOPIC_0125560238__p1494334516242">Type: string</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.9.3.2.4.1.3 "><p id="EN-US_TOPIC_0125560238__p179431845122412">Optional. This parameter must be carried in the request sent by federated users.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0125560238__section19319315217"><h4 class="sectiontitle">Request Elements</h4><p id="EN-US_TOPIC_0125560238__p5408778">In this request, you must configure the CORS of buckets in the request body. The configuration information is uploaded in the XML format. <a href="#EN-US_TOPIC_0125560238__table65776751">Table 2</a> lists the CORS configuration elements.</p>
|
|
|
|
<div class="tablenoborder"><a name="EN-US_TOPIC_0125560238__table65776751"></a><a name="table65776751"></a><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0125560238__table65776751" frame="border" border="1" rules="all"><caption><b>Table 2 </b>CORS configuration elements</caption><thead align="left"><tr id="EN-US_TOPIC_0125560238__row12020482"><th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.10.3.2.4.1.1"><p id="EN-US_TOPIC_0125560238__p34134946">Element</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.10.3.2.4.1.2"><p id="EN-US_TOPIC_0125560238__p13467214">Description</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.10.3.2.4.1.3"><p id="EN-US_TOPIC_0125560238__p17102575">Remarks</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0125560238__row43131373"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.1 "><p id="EN-US_TOPIC_0125560238__p3980335">CORSConfiguration</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.2 "><p id="EN-US_TOPIC_0125560238__p53971742">Indicates the <strong id="EN-US_TOPIC_0125560238__b15983633">CORSRules</strong> root node. The maximum size is 64 KB.</p>
|
|
<p id="EN-US_TOPIC_0125560238__p9634977">Type: Container</p>
|
|
<p id="EN-US_TOPIC_0125560238__p19605934">Ancestor: None</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.3 "><p id="EN-US_TOPIC_0125560238__p44576811">Mandatory</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0125560238__row65646981"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.1 "><p id="EN-US_TOPIC_0125560238__p15805238">CORSRule</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.2 "><p id="EN-US_TOPIC_0125560238__p5155867">Indicates a CORS rule. <strong id="EN-US_TOPIC_0125560238__b1868418351862">CORSConfiguration</strong> can contain a maximum of 100 rules.</p>
|
|
<p id="EN-US_TOPIC_0125560238__p14972060">Type: Container</p>
|
|
<p id="EN-US_TOPIC_0125560238__p530819">Ancestor: <strong id="EN-US_TOPIC_0125560238__b4777379">CORSConfiguration</strong></p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.3 "><p id="EN-US_TOPIC_0125560238__p51423381">Mandatory</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0125560238__row60157251"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.1 "><p id="EN-US_TOPIC_0125560238__p40899139">ID</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.2 "><p id="EN-US_TOPIC_0125560238__p24495972">Indicates the unique identifier of a rule. The value can contain a maximum of 255 characters.</p>
|
|
<p id="EN-US_TOPIC_0125560238__p19137160">Type: String</p>
|
|
<p id="EN-US_TOPIC_0125560238__p38016717">Ancestor: Rule</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.3 "><p id="EN-US_TOPIC_0125560238__p59455271">Optional</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0125560238__row65335398"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.1 "><p id="EN-US_TOPIC_0125560238__p57675884">AllowedMethod</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.2 "><p id="EN-US_TOPIC_0125560238__p41234998">Indicates a method that is allowed by a CORS rule.</p>
|
|
<p id="EN-US_TOPIC_0125560238__p35570664">Type: String</p>
|
|
<p id="EN-US_TOPIC_0125560238__p51700524">Valid values: <strong id="EN-US_TOPIC_0125560238__b62651540">GET</strong>, <strong id="EN-US_TOPIC_0125560238__b26992952">PUT</strong>, <strong id="EN-US_TOPIC_0125560238__b41609976">HEAD</strong>, <strong id="EN-US_TOPIC_0125560238__b38945471">POST</strong>, and <strong id="EN-US_TOPIC_0125560238__b14964925">DELETE</strong></p>
|
|
<p id="EN-US_TOPIC_0125560238__p466603">Ancestor: Rule</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.3 "><p id="EN-US_TOPIC_0125560238__p37794916">Mandatory</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0125560238__row4609929"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.1 "><p id="EN-US_TOPIC_0125560238__p37859935">AllowedOrigin</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.2 "><p id="EN-US_TOPIC_0125560238__p46755894">Indicates an origin that is allowed by a CORS rule. It is a character string and can contain a wildcard (*). Each <strong id="EN-US_TOPIC_0125560238__b18149865">AllowedOrigin</strong> can only contain one wildcard (*).</p>
|
|
<p id="EN-US_TOPIC_0125560238__p29131061">Type: String</p>
|
|
<p id="EN-US_TOPIC_0125560238__p60852964">Ancestor: Rule</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.3 "><p id="EN-US_TOPIC_0125560238__p30143027">Mandatory</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0125560238__row2851790"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.1 "><p id="EN-US_TOPIC_0125560238__p29668407">AllowedHeader</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.2 "><p id="EN-US_TOPIC_0125560238__p54330728">Indicates an allowed header (<strong id="EN-US_TOPIC_0125560238__b19214507">Access-Control-Request-Headers</strong>) in a CORS request. If a request contains <strong id="EN-US_TOPIC_0125560238__b38712842">Access-Control-Request-Headers</strong>, only a CORS request that matches the configuration of <strong id="EN-US_TOPIC_0125560238__b12871260">AllowedHeader</strong> is considered as a valid request. Each <strong id="EN-US_TOPIC_0125560238__b48732484">AllowedHeader</strong> can only contain one wildcard (*).</p>
|
|
<p id="EN-US_TOPIC_0125560238__p35939178">Type: String</p>
|
|
<p id="EN-US_TOPIC_0125560238__p55017151">Ancestor: Rule</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.3 "><p id="EN-US_TOPIC_0125560238__p27204259">Optional</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0125560238__row43511739"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.1 "><p id="EN-US_TOPIC_0125560238__p34789966">MaxAgeSeconds</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.2 "><p id="EN-US_TOPIC_0125560238__p66523870">Indicates the response time of the CORS that can be cached by a server. It is expressed in seconds.</p>
|
|
<p id="EN-US_TOPIC_0125560238__p61843920">Each <strong id="EN-US_TOPIC_0125560238__b11901342963">CORSRule</strong> can contain only one <strong id="EN-US_TOPIC_0125560238__b43301605">MaxAgeSeconds</strong>. It can be set to a negative value.</p>
|
|
<p id="EN-US_TOPIC_0125560238__p54170131">Type: Integer</p>
|
|
<p id="EN-US_TOPIC_0125560238__p17769131">Ancestor: Rule</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.3 "><p id="EN-US_TOPIC_0125560238__p30013513">Optional</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0125560238__row1686169"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.1 "><p id="EN-US_TOPIC_0125560238__p2362032">ExposeHeader</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.2 "><p id="EN-US_TOPIC_0125560238__p57106866">Indicates a supplemented header in CORS responses. The header provides additional information for servers. It cannot contain spaces.</p>
|
|
<p id="EN-US_TOPIC_0125560238__p44199752">Type: String</p>
|
|
<p id="EN-US_TOPIC_0125560238__p62253449">Ancestor: Rule</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.10.3.2.4.1.3 "><p id="EN-US_TOPIC_0125560238__p9364637">Optional</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0125560238__section48398424"><h4 class="sectiontitle">Response Syntax</h4><pre class="screen" id="EN-US_TOPIC_0125560238__screen701446412135">HTTP/1.1 status_code
|
|
Server: Server Name
|
|
x-amz-request-id: request id
|
|
x-amz-id-2: id
|
|
x-reserved: amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc
|
|
Date: date
|
|
Content-Length: 0</pre>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0125560238__section32932634"><h4 class="sectiontitle">Response Headers</h4><p id="EN-US_TOPIC_0125560238__p33594135">This response uses common headers. For details about common response headers, see section <a href="en-us_topic_0125560484.html">Common Response Headers</a>.</p>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0125560238__section27958252"><h4 class="sectiontitle">Response Elements</h4><p id="EN-US_TOPIC_0125560238__p25613652">This response involves no elements.</p>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0125560238__section50297679"><h4 class="sectiontitle">Error Responses</h4><p id="EN-US_TOPIC_0125560238__p61439917">No special error responses are returned. For details about error responses, see <a href="en-us_topic_0125560440.html#EN-US_TOPIC_0125560440__table30733758">Table 1</a>.</p>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0125560238__section51895228"><h4 class="sectiontitle">Sample Request</h4><pre class="screen" id="EN-US_TOPIC_0125560238__screen38607624121324">PUT /?cors HTTP/1.1
|
|
User-Agent: curl/7.19.0 (x86_64-suse-linux-gnu) libcurl/7.19.0 OpenSSL/0.9.8{ zlib/1.2.3 libidn/1.10
|
|
Host: bucketname.obs.example.com
|
|
Accept: */*
|
|
Date: Tue, 28 Apr 2015 08:56:07 +0000
|
|
Authorization: AWS D13E0C94E722DD69423C:QhHpU6Amg/2r6wIYdU3RXIx7Tlc=
|
|
Content-MD5: x3R4DBZgOrwsI6DwztrQCg==
|
|
Content-Length: 468
|
|
<CORSConfiguration>
|
|
<CORSRule>
|
|
<AllowedMethod>POST</AllowedMethod>
|
|
<AllowedMethod>GET</AllowedMethod>
|
|
<AllowedMethod>HEAD</AllowedMethod>
|
|
<AllowedMethod>PUT</AllowedMethod>
|
|
<AllowedMethod>DELETE</AllowedMethod>
|
|
<AllowedOrigin>obs.example.com</AllowedOrigin>
|
|
<AllowedOrigin>www.example.com</AllowedOrigin>
|
|
<AllowedHeader>AllowedHeader_1</AllowedHeader>
|
|
<AllowedHeader>AllowedHeader_2</AllowedHeader>
|
|
<MaxAgeSeconds>100</MaxAgeSeconds>
|
|
<ExposeHeader>ExposeHeader_1</ExposeHeader>
|
|
<ExposeHeader>ExposeHeader_2</ExposeHeader>
|
|
</CORSRule>
|
|
</CORSConfiguration></pre>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0125560238__section64403869"><h4 class="sectiontitle">Sample Response</h4><pre class="screen" id="EN-US_TOPIC_0125560238__screen12557160121330">HTTP/1.1 200 OK
|
|
Server: OBS
|
|
x-amz-request-id: C2D2F581B3C5AF6C6698322AB56836F6
|
|
x-amz-id-2: lDGZAj4h+A33eYauDCTsPvFSHzBXEtZon6Eg1idIZl18/2/odotyqJUJ/lTh80uA
|
|
x-reserved: amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc
|
|
Date: Tue, 28 Apr 2015 08:56:07 GMT
|
|
Content-Length: 0</pre>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="en-us_topic_0125560493.html">Operations on Buckets</a></div>
|
|
</div>
|
|
</div>
|
|
|