Configura regras de compartilhamento de recursos de origem cruzada (CORS) para um bucket.
Sintaxe do comando
ossutil api put-bucket-cors --bucket value --cors-configuration value [flags]
|
Parâmetro |
Tipo |
Descrição |
|
--bucket |
string |
Nome do bucket para configurar as regras de CORS. |
|
--cors-configuration |
string |
Contêiner que armazena as regras de CORS do bucket. |
O comando put-bucket-cors corresponde à operação PutBucketCors. Para obter mais informações sobre os parâmetros do comando, consulte PutBucketCors.
--cors-configuration
A opção --cors-configuration aceita os formatos XML e JSON:
-
Formato XML:
<CORSConfiguration> <CORSRule> <AllowedOrigin>string</AllowedOrigin> ... <AllowedMethod>string</AllowedMethod> ... <AllowedHeader>string</AllowedHeader> <ExposeHeader>string</ExposeHeader> ... <MaxAgeSeconds>integer</MaxAgeSeconds> </CORSRule> ... <ResponseVary>boolean</ResponseVary> </CORSConfiguration>Nota...indica suporte a vários nós. -
Formato JSON:
{ "CORSRule": [ { "AllowedOrigin": ["string", ...], "AllowedMethod": ["string", ...], "AllowedHeader": "string", "ExposeHeader": ["string", ...], "MaxAgeSeconds": integer }, ... ], "ResponseVary": boolean }NotaO formato JSON não inclui o nó raiz do XML.
Para obter mais informações, consulte Opções de linha de comando.
Exemplos
Nos exemplos a seguir, a source permitida para requisições de origem cruzada é www.aliyun.com, os métodos de requisição permitidos são PUT e GET e o tempo de resposta do cache é de 10.000 segundos.
-
Use o arquivo de configuração XML cors-configuration.xml:
<CORSConfiguration> <CORSRule> <AllowedOrigin>www.aliyun.com</AllowedOrigin> <AllowedMethod>PUT</AllowedMethod> <AllowedMethod>GET</AllowedMethod> <MaxAgeSeconds>10000</MaxAgeSeconds> </CORSRule> </CORSConfiguration>ossutil api put-bucket-cors --bucket examplebucket --cors-configuration file://cors-configuration.xml -
Use o arquivo de configuração JSON cors-configuration.json:
{ "CORSRule": { "AllowedOrigin": ["www.aliyun.com"], "AllowedMethod": ["PUT","GET"], "MaxAgeSeconds": 10000 } }ossutil api put-bucket-cors --bucket examplebucket --cors-configuration file://cors-configuration.json -
Especifique os parâmetros de configuração em JSON:
ossutil api put-bucket-cors --bucket examplebucket --cors-configuration "{\"CORSRule\":{\"AllowedOrigin\":[\"www.aliyun.com\"],\"AllowedMethod\":[\"PUT\",\"GET\"],\"MaxAgeSeconds\":10000}}"