Skip to contents

Creates the bucket if it does not exist yet. Buckets are private by default, public read access gets granted by connecting a custom domain or by enabling the r2.dev public development URL of the bucket. Public access can also be enabled on existing buckets, but this function never turns it off.

Usage

create_r2_bucket(r2_bucket, public = FALSE, custom_domain = NULL)

Arguments

r2_bucket

bucket name, or the bucket as r2://bucket like the other functions address it.

public

FALSE (default) or TRUE: enable public read access via the r2.dev URL. Ignored if custom_domain is set.

custom_domain

domain to connect to the bucket for public read access, like data.example.com, optional. The r2.dev URL does not get enabled then.

Value

(invisibly) the public base URL of the bucket if it is publicly accessible, otherwise NULL.

Details

Cloudflare rate limits access via r2.dev, for heavier use connect a custom domain. Each custom domain can only serve one bucket, use subdomains like data.example.com to serve several buckets from one zone.

Credentials

The R2 account id and the value of an R2 API token with admin read and write permissions have to be in the R2_ACCOUNT_ID and R2_API_TOKEN environment variables. For connecting a custom domain the token also needs Zone Read permission for the domain's zone, which has to be an active zone in the same Cloudflare account. With Zone Cache Purge permission as well, upload_parquet() and remove_parquet() purge changed files from the cache.