Overview
TheR2Credentials struct stores authentication credentials and configuration for connecting to a Cloudflare R2 bucket. It provides computed properties for endpoint URLs and methods for generating public URLs for uploaded objects.
Properties
UUID
required
Unique identifier for this credential set
String
required
Cloudflare account ID used to construct the R2 endpoint URL
String
required
R2 access key ID for S3-compatible authentication
String
required
R2 secret access key for S3-compatible authentication
String
required
Name of the R2 bucket to use for storage operations
String?
Optional custom domain for public URLs. If provided, public URLs will use this domain instead of the default R2 endpoint
Bool
Returns
true if any required credential fields are emptyURL
The S3-compatible endpoint URL for this R2 account, formatted as:
Methods
publicURL(forKey:)
Constructs the public URL for an uploaded object.String
required
The object key (path) in the R2 bucket
URL - The public URL for accessing the object
Behavior:
- If
customDomainis set, returns{customDomain}/{key} - Otherwise, returns
{endpoint}/{bucketName}/{key}
Source Code
R2Credentials.swift
Protocols
Sendable- Thread-safe value typeCodable- Can be encoded/decoded to/from JSON or other formatsEquatable- Can be compared for equalityIdentifiable- Has a uniqueidproperty