R2 bucket management over the Cloudflare API: list, create, get, and delete buckets. Object reads and writes use R2's S3-compatible API — use the aws-s3 package against https://{account_id}.r2.cloudflarestorage.com (region auto) with an R2 access key pair.

Context Vars

Optional
  • cloudflare.token
  • cloudflare.account.id

Functions

bucket-suffix

fn (name: Str): Str

create-bucket

fn (name: Str): Map
fn (name: Str, options: Map): Map
fn (name: Str, options: Map, opts: Map): Map

POST /accounts/{account_id}/r2/buckets - Create a bucket. options: location_hint (apac, eeur, enam, weur, wnam, oc), storage_class (Standard, InfrequentAccess), jurisdiction.

Example

::cloudflare::r2/create-bucket("exports", {location_hint: "enam"})

create-bucket-body

fn (name: Str, options: Map): Map

The create body: {name, locationHint?, storageClass?} from options (location_hint/locationHint, storage_class/storageClass). Exposed for testing.

delete-bucket

fn (name: Str): Any
fn (name: Str, jurisdiction: Str?): Any
fn (name: Str, opts: Map): Any
fn (name: Str, jurisdiction: Str?, opts: Map): Any

DELETE /accounts/{account_id}/r2/buckets/{name} - Delete an empty bucket (R2 refuses a bucket that still holds objects).

get-bucket

fn (name: Str): Map
fn (name: Str, jurisdiction: Str?): Map
fn (name: Str, opts: Map): Map
fn (name: Str, jurisdiction: Str?, opts: Map): Map

GET /accounts/{account_id}/r2/buckets/{name} - One bucket: {name, creation_date, location, storage_class, jurisdiction}.

jurisdiction-headers

fn (jurisdiction: Str?): Map

The cf-r2-jurisdiction header for a jurisdiction ("eu", "fedramp", …), or no header for null/"default". Exposed for testing.

list-all-buckets

fn (): Vec
fn (params: Map): Vec
fn (params: Map, max: Int): Vec
fn (params: Map, opts: Map): Vec
fn (params: Map, max: Int, opts: Map): Vec

Every bucket matching params, following cursors up to max buckets (default 10000).

list-buckets

fn (): ::cloudflare::api/ListPage
fn (params: Map): ::cloudflare::api/ListPage
fn (params: Map, opts: Map): ::cloudflare::api/ListPage

GET /accounts/{account_id}/r2/buckets - One page of buckets. params: name_contains, start_after, per_page (1–1000), cursor, order (name), direction, and jurisdiction (sent as the cf-r2-jurisdiction header). Returns a ListPage whose result is the bucket list.

s3-endpoint

fn (account-id: Str): Str
fn (account-id: Str, jurisdiction: Str?): Str

The S3-compatible endpoint for object I/O with aws-s3: https://{account_id}.r2.cloudflarestorage.com (.eu. / .fedramp. inserted for those jurisdictions).

send-json

fn (method: Str, suffix: Str, body: Any, jurisdiction: Str?, opts: Map): Any