The referer command is used to add, modify, query, or delete hotlink protection 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 hotlink protection, see Configure hotlink protection.

Command syntax

  • Add or modify hotlink protection configurations for a specified bucket
    ./ossutil referer --method put oss://bucket referer-value [--disable-empty-referer]
    If the specified bucket does not have hotlink protection configured, you can run this command to add hotlink protection configurations. If the specified bucket has hotlink protection configured, you can run this command to overwrite the existing hotlink protection configurations.
    • referer-value: specifies a Referer whitelist. Only the specified domain names are allowed to access OSS resources. Asterisks (*) and question marks (?) are supported as wildcards. Multiple domain names must be separated with spaces.
    • --disable-empty-referer: specifies whether the Referer field can be left empty in an access request. If this option is specified, the Referer field cannot be left empty. If you do not allow empty Referers fields, only HTTP or HTTPS requests which include an allowed Referer field value can access the objects in the bucket.
  • Query the hotlink protection configurations of a bucket
    ./ossutil referer --method get oss://bucket  [local_xml_file]

    The local_xml_file parameter specifies the name of the configuration file. If this parameter is specified, the hotlink protection configurations are saved as a local file. If this parameter is not specified, ossutil displays the hotlink protection configurations.

  • Delete the hotlink protection configurations of a bucket
    ./ossutil referer --method delete oss://bucket

Examples

  • Configure hotlink protection and specify the Referer field
    ./ossutil referer --method put oss://bucket1 www.test1.com www.test2.com --disable-empty-referer
  • Query the hotlink protection configurations of a bucket
    ./ossutil referer --method get oss://bucket1  /file/referer.xml
  • Delete the hotlink protection configurations of a bucket
    ./ossutil referer --method delete oss://bucket1

Common options

The following table describes the options you can add to the referer command.
Option Description
--method Specifies the HTTP request method. Valid values:
  • put: adds or modifies hotlink protection configurations.
  • get: queries hotlink protection configurations.
  • delete: deletes hotlink protection configurations.
--disable-empty-referer Specifies whether the Referer field can be left empty. If this option is specified, the Referer field cannot be left empty. If you do not allow empty Referers fields, only HTTP or HTTPS requests which include an allowed Referer field value can access the objects in the bucket.
--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.