Skip to content
Start here

Put Bucket CORS Policy

client.R2.Buckets.CORS.Update(ctx, bucketName, params) (*BucketCORSUpdateResponse, error)
PUT/accounts/{account_id}/r2/buckets/{bucket_name}/cors

Set the CORS policy for a bucket.

Security

API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
ParametersExpand Collapse
bucketName string

Name of the bucket.

maxLength64
minLength3
params BucketCORSUpdateParams
AccountID param.Field[string]

Path param: Account ID.

maxLength32
Rules param.Field[[]BucketCORSUpdateParamsRule]Optional

Body param

Allowed BucketCORSUpdateParamsRulesAllowed

Object specifying allowed origins, methods and headers for this CORS rule.

Methods []BucketCORSUpdateParamsRulesAllowedMethod

Specifies the value for the Access-Control-Allow-Methods header R2 sets when requesting objects in a bucket from a browser.

One of the following:
const BucketCORSUpdateParamsRulesAllowedMethodGet BucketCORSUpdateParamsRulesAllowedMethod = "GET"
const BucketCORSUpdateParamsRulesAllowedMethodPut BucketCORSUpdateParamsRulesAllowedMethod = "PUT"
const BucketCORSUpdateParamsRulesAllowedMethodPost BucketCORSUpdateParamsRulesAllowedMethod = "POST"
const BucketCORSUpdateParamsRulesAllowedMethodDelete BucketCORSUpdateParamsRulesAllowedMethod = "DELETE"
const BucketCORSUpdateParamsRulesAllowedMethodHead BucketCORSUpdateParamsRulesAllowedMethod = "HEAD"
Origins []string

Specifies the value for the Access-Control-Allow-Origin header R2 sets when requesting objects in a bucket from a browser.

Headers []stringOptional

Specifies the value for the Access-Control-Allow-Headers header R2 sets when requesting objects in this bucket from a browser. Cross-origin requests that include custom headers (e.g. x-user-id) should specify these headers as AllowedHeaders.

ID stringOptional

Identifier for this rule.

ExposeHeaders []stringOptional

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 float64Optional

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.

Jurisdiction param.Field[BucketCORSUpdateParamsCfR2Jurisdiction]Optional

Header param: Jurisdiction where objects in this bucket are guaranteed to be stored.

const BucketCORSUpdateParamsCfR2JurisdictionDefault BucketCORSUpdateParamsCfR2Jurisdiction = "default"
const BucketCORSUpdateParamsCfR2JurisdictionEu BucketCORSUpdateParamsCfR2Jurisdiction = "eu"
const BucketCORSUpdateParamsCfR2JurisdictionFedramp BucketCORSUpdateParamsCfR2Jurisdiction = "fedramp"
ReturnsExpand Collapse
type BucketCORSUpdateResponse interface{…}

Put Bucket CORS Policy

package main

import (
  "context"
  "fmt"

  "github.com/stainless-sdks/cloudflare-go"
  "github.com/stainless-sdks/cloudflare-go/option"
  "github.com/stainless-sdks/cloudflare-go/r2"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  cors, err := client.R2.Buckets.CORS.Update(
    context.TODO(),
    "example-bucket",
    r2.BucketCORSUpdateParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", 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
}