Skip to main content

cors

Creates, updates, deletes, gets or lists a cors resource.

Overview

Namecors
TypeResource
Idcloudflare.r2.cors

Fields

The following fields are returned by SELECT queries:

Success Response.

NameDatatypeDescription
idstringIdentifier for this rule. (example: Allow Local Development)
allowedobjectObject specifying allowed origins, methods and headers for this CORS rule.
exposeHeadersarraySpecifies 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.
maxAgeSecondsnumberSpecifies 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:

NameAccessible byRequired ParamsOptional ParamsDescription
listselectbucket_name, account_idcf-r2-jurisdictionGet the CORS policy for a bucket.
updatereplacebucket_name, account_idcf-r2-jurisdictionSet the CORS policy for a bucket.
deletedeletebucket_name, account_idcf-r2-jurisdictionDelete 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.

NameDatatypeDescription
account_idstringThe Cloudflare account ID.
bucket_namestringThe R2 bucket name.
cf-r2-jurisdictionstring

SELECT examples

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

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 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 }}'
;