cors
Creates, updates, deletes, gets or lists a cors resource.
Overview
| Name | cors |
| Type | Resource |
| Id | cloudflare.r2.cors |
Fields
The following fields are returned by SELECT queries:
- list
Success Response.
| Name | Datatype | Description |
|---|---|---|
id | string | Identifier for this rule. (example: Allow Local Development) |
allowed | object | Object specifying allowed origins, methods and headers for this CORS rule. |
exposeHeaders | array | Specifies the headers that can be exposed back, and accessed by, the JavaScript making the cross-origin request. If you need to access headers beyond the safelisted response headers, such as Content-Encoding or cf-cache-status, you must specify it here. |
maxAgeSeconds | number | Specifies the amount of time (in seconds) browsers are allowed to cache CORS preflight responses. Browsers may limit this to 2 hours or less, even if the maximum value (86400) is specified. |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
list | select | bucket_name, account_id | cf-r2-jurisdiction | Get the CORS policy for a bucket. |
update | replace | bucket_name, account_id | cf-r2-jurisdiction | Set the CORS policy for a bucket. |
delete | delete | bucket_name, account_id | cf-r2-jurisdiction | Delete the CORS policy for a bucket. |
Parameters
Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.
| Name | Datatype | Description |
|---|---|---|
account_id | string | The Cloudflare account ID. |
bucket_name | string | The R2 bucket name. |
cf-r2-jurisdiction | string |
SELECT examples
- list
Get the CORS policy for a bucket.
SELECT
id,
allowed,
exposeHeaders,
maxAgeSeconds
FROM cloudflare.r2.cors
WHERE bucket_name = '{{ bucket_name }}' -- required
AND account_id = '{{ account_id }}' -- required
AND cf-r2-jurisdiction = '{{ cf-r2-jurisdiction }}'
;
REPLACE examples
- update
Set the CORS policy for a bucket.
REPLACE cloudflare.r2.cors
SET
rules = '{{ rules }}'
WHERE
bucket_name = '{{ bucket_name }}' --required
AND account_id = '{{ account_id }}' --required
AND cf-r2-jurisdiction = '{{ cf-r2-jurisdiction}}'
RETURNING
errors,
messages,
result,
success;
DELETE examples
- delete
Delete the CORS policy for a bucket.
DELETE FROM cloudflare.r2.cors
WHERE bucket_name = '{{ bucket_name }}' --required
AND account_id = '{{ account_id }}' --required
AND cf-r2-jurisdiction = '{{ cf-r2-jurisdiction }}'
;