class R2Storage
implements IStorage
Since 0.2.0

Object storage backed by Cloudflare R2.

getStream is implemented, so a download can be piped straight to the response through IResponse.stream() without buffering the object.

getSignedUrl throws: the R2 Workers binding exposes no presigned-URL capability at all. Serving an object through a Worker route, or fronting the bucket with a custom domain, are the available alternatives, and the error says so.

Constructors

R2Storage(
bucket: IR2Bucket,
)
Parameters
bucket: IR2Bucket

The R2 bucket binding

optional
options: R2StorageOptions

Key prefix

Methods

delete(path: string): Promise<boolean>

Deletes an object.

exists(path: string): Promise<boolean>

Reports whether an object exists.

get(path: string): Promise<Uint8Array>

Retrieves an object.

getSignedUrl(
path: string,
_options: SignedUrlOptions
): Promise<string>

Always throws — R2 bindings cannot presign.

The unused _options is kept, not deleted. Dropping it would narrow the exported class below IStorage, so a consumer holding an R2Storage directly could no longer pass SignedUrlOptions — the interface still declares it. An underscore is the sanctioned way to mark a parameter a contract requires and an implementation cannot use.

getStream(path: string): Promise<ReadableStream<Uint8Array>>

Streams an object without buffering it.

put(
path: string,
data: Uint8Array,
options?: PutObjectOptions
): Promise<void>

Writes an object, translating PutObjectOptions into R2's own spelling: the content type lives under httpMetadata, user metadata under customMetadata. Without this every object was served as application/octet-stream (X8-6).

Usage

import { R2Storage } from "cloudflare-plugin/src/index.ts";