設置CORS規則
更新時間 2024-10-31 15:40:29
最近更新時間: 2024-10-31 15:40:29
分享文章
接口介紹
此接口用于在指定的Bucket 上設定一個跨域資源共享(CORS)的規則,如果原規則存在則覆蓋原規則。
接口約束
無
請求URI
PUT /v1/cors/{bucket}
路徑參數
| 參數 | 是否必填 | 參數類型 | 說明 | 示例 |
|---|---|---|---|---|
| bucket | 是 | String | 桶名稱 | testBucket |
Query參數
| 參數 | 是否必填 | 參數類型 | 說明 | 示例 | 下級對象 |
|---|---|---|---|---|---|
| cors | 是 | String | 固定參數 |
注:如果query中的參數為固定參數,不需要帶值value。
請求參數
請求頭header參數
| 參數 | 是否必填 | 參數類型 | 說明 | 示例 | 下級對象 |
|---|---|---|---|---|---|
| Content-Type | 是 | String | 消息體格式 | application/xml |
請求體body參數
| 參數 | 是否必填 | 參數類型 | 說明 | 示例 | 下級對象 |
|---|---|---|---|---|---|
| CORSConfiguration | 是 | Array of Objects | 最多100 個CORSRule 元素的容器 | CORSConfiguration |
表 CORSConfiguration
| 參數 | 是否必填 | 參數類型 | 說明 | 示例 | 下級對象 |
|---|---|---|---|---|---|
| CORSRule | 是 | Array of Objects | 一組源和方法 | CORSRule |
表 CORSRule
| 參數 | 是否必填 | 參數類型 | 說明 | 示例 | 下級對象 |
|---|---|---|---|---|---|
| AllowedHeader | 否 | String | 設置允許哪些header,注意: 只能使用一個星號(*)通配符,且不支持使用這些字符:(<,&) | * | |
| AllowedMethod | 否 | String | 允許執行的跨域請求方法,取值范圍為:GET,PUT,DELETE,POST,HEAD | PUT | |
| AllowedOrigin | 是 | String | 指定允許的跨域請求的來源,允許使用多個元素來指定多個允許的來源, AllowedOrigin中只能使用一個星號(*)通配符 | //example.daliqc.cn | |
| ExposeHeader | 否 | String | 指定允許用戶從應用程序中訪問的響應頭,不支持使用這些字符:(<,&) | test123 | |
| MaxAgeSeconds | 否 | Integer | 指定瀏覽器對特定資源的預取請求返回結果的緩存時間,單位為秒,如果參數<0,按0處理 | 30 |
響應參數
無
請求示例
PUT /v1/cors/testbucket?cors HTTP/1.1
請求頭header
Content-Type:application/xml
請求體body
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>//example.daliqc.cn</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
<ExposeHeader>test123</ExposeHeader>
<MaxAgeSeconds>30</MaxAgeSeconds>
</CORSRule>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
</CORSRule>
</CORSConfiguration>
響應示例
HTTP/1.1 200 OK
x-amz-request-id: tx000000000000000000274-00632298b2-3b9ae-default
Date: Wed, 06 Sep 2017 12:00:00 GMT
狀態碼
| HTTP狀態 | 錯誤碼 | 描述 |
|---|---|---|
| 200 | 操作成功 | |
| 400 | InvalidBucketName | 桶的名字不合法 |
| 400 | MalformedXML | 跨域設置xml格式有問題 |
| 403 | AccessDenied | 用戶沒有權限執行操作 |
| 404 | NoSuchBucket | 操作指定的桶不存在 |