The cors command is used to add, modify, query, or delete the CORS configurations for a bucket.

Note
  • The commands described in this topic apply to Linux. To use the commands in other systems, replace ./ossutil in the command with the actual executable program name. For example, you can use the help command in 32-bit Windows systems by running ossutil32.exe help.
  • For more information about CORS, see Set CORS rules.

Command syntax

  • Add or modify CORS configurations for a specified bucket
    ./ossutil cors --method put oss://bucket  local_xml_file
    ossutil reads the local_xml_file configuration file. If the bucket has no CORS rules configured, ossutil adds the corresponding CORS rules to this configuration file. If the bucket has CORS rules configured, the new rules overwrite the existing rules.
    Note The local_xml_file configuration file is in the XML format as follows:
    <? xml version="1.0" encoding="UTF-8"? >
       <CORSConfiguration>
         <CORSRule>
             <AllowedOrigin>www.aliyun.com</AllowedOrigin>
             <AllowedMethod>PUT</AllowedMethod>
             <MaxAgeSeconds>10000</MaxAgeSeconds>
         </CORSRule>
     </CORSConfiguration>
  • Query CORS configurations for a bucket
    ./ossutil cors --method get oss://bucket  [local_xml_file]

    The local_xml_file parameter specifies the name of the configuration file. If this parameter is specified, ossutil saves the obtained CORS configurations as a local file. If this parameter is not specified, ossutil displays the obtained CORS configurations.

  • Delete CORS configurations for a bucket
    ./ossutil cors --method delete oss://bucket

Examples

  • Add CORS configurations for a bucket
    ./ossutil cors --method put oss://bucket1  /file/cors.xml
  • Query CORS configurations for a bucket
    ./ossutil cors --method get oss://bucket1  /file/cors.xml
  • Delete CORS configurations for a bucket
    ./ossutil cors --method delete oss://bucket1  

Common options

The following table describes the options you can add to the cors command.
Option Description
--method Specifies the HTTP request method. Valid values:
  • put: adds or modifies CORS configurations.
  • get: queries CORS configurations.
  • delete: deletes CORS configurations.
--loglevel Specifies the log level. The default value is null, indicating that no log files are generated. Valid values:
  • info: generates prompt logs.
  • debug: generates detailed logs that contain corresponding HTTP request and response information.
--proxy-host Specifies the URL of the proxy server. HTTP, HTTPS, and SOCKS5 proxies are supported. An example of the URL is http://120.79. **.**:3128 or socks5://120.79. **. **:1080.
--proxy-user Specifies the username for the proxy server. The default value is null.
--proxy-pwd Specifies the password for the proxy server. The default value is null.
Note For more information about common options, see View all supported options.