• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. User Guide
  4. OBS Console Operation Guide
  5. CORS
  6. Configuring CORS

Configuring CORS

This section describes how to use CORS in HTML5 to implement cross-origin access.

Prerequisites

Static website hosting has been enabled.

Procedure

  1. In the bucket list on the OBS Console, click the target bucket to go to the Summary page.
  2. In the navigation tree on the left, click Static Website Hosting.
  3. Click the CORS Rule card.
  4. Click AddFigure 1 displays the subsequent page.

    NOTE:

    You can set a maximum of 100 CORS rules for OBS.

    Figure 1 CORS Rule

  5. In the CORS Rule dialog box, configure Allowed OriginAllowed MethodAllowed HeaderExposed Header, and Cache Duration (s).

    Table 1 describes the parameters of CORS rules.

    Table 1 Parameters in CORS rules

    Parameter

    Description

    Allowed Origin

    Mandatory

    Requests from this origin can access the bucket.

    Multiple matching rules are allowed. One rule occupies one line, and allows one wildcard character (*) at most. For example:

    http://rds.example.com
    https://*.vbs.example.com

    Allowed Method

    Mandatory

    Specifies the acceptable operation type of buckets and objects.

    The methods include GET, POST, PUT, DELETE, and HEAD.

    Allowed Header

    Optional

    Specifies the allowed header of cross-origin requests.

    Only CORS requests matching the allowed header are valid.

    You can enter multiple allowed headers (one per line) and each line can contain one wildcard character (*) at most. Spaces and special characters including &:< are not allowed.

    Exposed Header

    Optional

    Specifies the exposed header in CORS responses, providing additional information for clients.

    You can enter multiple exposed headers (one per line). Spaces and special characters including *&:< are not allowed.

    Cache Duration (s)

    Mandatory

    Specifies the duration that your browser can cache CORS responses, expressed in seconds. The default value is 100.

  6. Click OK.

    A message is displayed indicating that CORS configuration of the bucket is successful. The configuration of CORS takes effect within two minutes.

    After CORS is successfully configured, only the addresses specified in Allowed Origin can access a bucket on OBS using the method specified in Allowed Method. For example, you configure CORS parameters of bucket testbucket as follows:

    • Allowed Originwww.examlple.com
    • Allowed MethodGET
    • Allowed Header: left blank
    • Exposed Header: left blank
    • Cache Duration (s)100

Follow-up Procedure

You can click Edit or Delete to edit or delete a configured CORS rule based on site requirements.