Unlock the Power of AI

1 million free tokens

88% Price Reduction

NaNDayNaN:NaN:NaN
Activate Now
This topic was translated by AI and is currently in queue for revision by our editors. Alibaba Cloud does not guarantee the accuracy of AI-translated content. Request expedited revision

Configure CORS

Updated at: 2025-04-10 03:08

If an "Access-Control-Allow-Origin" related error occurs or the system prompts that the resource supports cross-origin access when you use ApsaraVideo Player SDK for Web to play videos, you need to enable CORS for your playback domain. This topic describes how to configure CORS for the web player and OSS playback.

Configure CORS for using the HTML5 player to play FLV and M3U8 videos

If the following error message is returned, you must enable CORS for the domain name for playback to resolve this issue:

No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://localhost:9030' is therefore not allowed access.

Add HTTP headers to enable CORS. For more information, see Custom HTTP response headers.

  1. Log on to the ApsaraVideo VOD console.

  2. In the System Management section of the left-side navigation pane of the ApsaraVideo VOD console, click CDN Configuration > Domain Names to go to the Domain Names page.

    截屏2025-04-08 15

  3. On the Domain Names page, select the domain name that you want to configure, and click Configure in the Actions column.

  4. Click Cache in the left-side navigation pane, and then click Custom HTTP Response Header. Click Add.

    截屏2025-04-08 16

  5. In the response header parameters, select Access-Control-Allow-Origin to specify the allowed origin of cross-origin requests.

    截屏2025-04-08 16

  6. Enter the corresponding response header value and click Confirm.

    Note
    • The response header value can be set to an asterisk (*), which indicates any origin.

    • If the response header value is not an asterisk (*), you can configure a single or multiple IP addresses, domain names, or a combination of IP addresses and domain names. Separate them with commas (,).

    • If the response header value is not an asterisk (*), it must include the protocol header "http://" or "https://".

    • Port numbers are supported.

    • Wildcard domain names are supported.

  7. Then add the method value for the corresponding domain name. Click Add and select Access-Control-Allow-Methods with a value of POST or GET. If you need to add both POST and GET, separate them with a comma (,). The following figure shows an example.

    截屏2025-04-08 16

Note

If the URL of a media segment file and the URL of the M3U8 video belong to different domain names, you need to configure the preceding HTTP headers for the domain name of the media segment file.

Configure CORS for playing videos that are stored in OSS

If you want the player to access the OSS bucket in which videos are stored, you need to configure CORS for the OSS bucket. For more information, see Configure CORS.

Set the following parameters to create a CORS rule:

  • Source: *.

  • Allowed Methods: Select GET, POST, PUT, DELETE, and HEAD.

  • Allowed Headers: *.

  • Exposed Headers: ETag.

Important

Specify this rule as the first of all CORS rules.

The following figure shows an example.OSS跨域示例图

Verify that CORS is enabled

To verify that CORS is enabled, perform the following steps:

  1. Open the developer tools in your browser (usually by pressing F12 or right-clicking and selecting "Inspect").

  2. Switch to the Network tab.

  3. Access the page that contains cross-origin requests to trigger the requests.

  4. Find your video request in the network request list and click it to view the details.

  5. In the request details, check the Response Headers section to confirm whether the Access-Control-Allow-Origin response header exists and whether its value matches your configuration.

If the Access-Control-Allow-Origin response header exists and its value is correct, CORS is enabled.

  • On this page (1)
  • Configure CORS for using the HTML5 player to play FLV and M3U8 videos
  • Configure CORS for playing videos that are stored in OSS
  • Verify that CORS is enabled
Feedback
phone Contact Us

Chat now with Alibaba Cloud Customer Service to assist you in finding the right products and services to meet your needs.

alicare alicarealicarealicare