Configuring CORS
This section describes how to use CORS in HTML5 to implement cross-origin access.
You can create CORS rules or replicate existing CORS rules from another bucket.
Prerequisites
Static website hosting has been configured. For details about how to configure static website hosting, see Configuring Static Website Hosting.
Creating a CORS Rule
- In the navigation pane on the left of OBS Console, choose Object Storage.
- In the bucket list, click a bucket name, and then the Overview page of the bucket is displayed.
- On the right of the Overview page, select CORS Rules in the Basic Configurations area. The CORS Rules page is displayed.
Alternatively, you can choose Permissions > CORS Rules in the navigation pane.
- Click Create. The Create CORS Rule dialog box is displayed. See Figure 1 for details.
You can set a maximum of 100 CORS rules for one bucket.
- In the CORS Rule dialog box, configure Allowed Origin, Allowed Method, Allowed Header, Exposed Header, and Cache Duration (s).
If CDN acceleration is enabled for the bucket, HTTP header must be configured on CDN. For details, see HTTP Header Settings.
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. 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.
- 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 in OBS using the method specified in Allowed Method. For example, you can configure CORS parameters of bucket testbucket as follows:
- Allowed Origin: https://www.example.com
- Allowed Method: GET
- Allowed Header: *
- Exposed Header: *
- Cache Duration (s): 100
Replicating CORS Rules
- In the navigation pane on the left of OBS Console, choose Object Storage.
- In the bucket list, click a bucket name, and then the Overview page of the bucket is displayed.
- On the right of the Overview page, click CORS Rules in the Basic Configurations area. The CORS Rules page is displayed.
Alternatively, you can choose Permissions > CORS Rules in the navigation pane.
- Click Replicate.
- Select a replication source, that is, the source bucket for which the CORS rules were configured.
- The CORS rules replicated from a source bucket will not overwrite existing rules in the destination bucket, and any that conflict with the existing ones will not be replicated.
- The version of both the source and destination buckets must be 3.0.
- You can remove the rules that you do not want to replicate.
- There can be 100 CORS rules at most in a bucket. If the number of rules you will replicate plus the number of existing rules in the destination bucket exceeds 100, the replication will fail. Before replicating the rules, delete some if necessary.
Figure 2 Replicating CORS rules
- Click OK to replicate the CORS rules to the destination bucket.
Last Article: CORS Overview
Next Article: URL Validation

Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.