Set Bucket CORS Policy
client.r2.buckets.cors.update(stringbucketName, CORSUpdateParams { account_id, rules, cfR2Jurisdiction } params, RequestOptionsoptions?): CORSUpdateResponse
PUT/accounts/{account_id}/r2/buckets/{bucket_name}/cors
Replaces the Cross-Origin Resource Sharing (CORS) rules for an R2 bucket. Rules specify which origins, methods, and headers are allowed for browser requests to objects in the bucket.
Security
API Token
The preferred authorization scheme for interacting with the Cloudflare API. Create a token.
Example:
Set Bucket CORS Policy
import Cloudflare from 'cloudflare';
const client = new Cloudflare({
apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});
const cors = await client.r2.buckets.cors.update('example-bucket', {
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
});
console.log(cors);{
"errors": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"messages": [
"string"
],
"result": {},
"success": true
}Returns Examples
{
"errors": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"messages": [
"string"
],
"result": {},
"success": true
}