Cloudflare - v1.3.0
    Preparing search index...

    Class R2Binding<E>

    Accessor for the R2 bucket binding (r2_buckets in wrangler.json).

    const storage = new R2Binding() // binding name from the configuration layer
    await storage.put(ctx.env, 'reports/2026-07.csv', body)
    const object = await storage.get(ctx.env, 'reports/2026-07.csv')

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    Type Parameters

    Hierarchy (View Summary)

    Index
    • get name(): string

      The binding name this instance resolves.

      Returns string

      The binding name as declared in wrangler.json.

    • Deletes one or more objects.

      Deleting a key that does not exist is not an error.

      Parameters

      • env: E

        The Worker environment.

      • keys: string | string[]

        A single object key, or a list of keys.

      Returns Promise<void>

    • Reads an object, body included.

      Parameters

      • env: E

        The Worker environment.

      • key: string

        The object key.

      • Optionaloptions: R2GetOptions

        Get options — range and conditional headers.

      Returns Promise<R2ObjectBody>

      The object, or null when it does not exist.

      MissingBindingError When the R2 binding is absent.

    • Reads an object's body and parses it as JSON.

      Type Parameters

      • T = unknown

      Parameters

      • env: E

        The Worker environment.

      • key: string

        The object key.

      Returns Promise<T>

      The parsed body, or null when the object does not exist.

    • Reads an object's body as text.

      Parameters

      • env: E

        The Worker environment.

      • key: string

        The object key.

      Returns Promise<string>

      The body as text, or null when the object does not exist.

    • Reads an object's metadata without transferring its body.

      Parameters

      • env: E

        The Worker environment.

      • key: string

        The object key.

      Returns Promise<R2Object>

      The object metadata, or null when it does not exist.

    • Checks whether the binding is available on the given environment.

      Use this to degrade gracefully when a binding is optional.

      Parameters

      • env: E

        The Worker environment.

      Returns boolean

      true when the binding is present.

    • Lists objects in the bucket.

      Parameters

      • env: E

        The Worker environment.

      • Optionaloptions: R2ListOptions

        List options — prefix, delimiter, limit, and cursor.

      Returns Promise<R2Objects>

      The matched objects and pagination state.

      Results are paginated — check truncated and pass the returned cursor back in to read the next page.

    • Writes an object.

      Parameters

      • env: E

        The Worker environment.

      • key: string

        The object key.

      • value: string | ReadableStream<any> | ArrayBuffer | ArrayBufferView | Blob

        The object body.

      • Optionaloptions: R2PutOptions

        Put options — HTTP metadata, custom metadata, and checksums.

      Returns Promise<R2Object>

      The stored object's metadata.

    • Serialises a value to JSON and writes it as an object.

      Parameters

      • env: E

        The Worker environment.

      • key: string

        The object key.

      • value: unknown

        The value to serialise and store.

      • options: R2PutOptions = {}

        Put options. The JSON content type is applied when unset.

      Returns Promise<R2Object>

      The stored object's metadata.

    • Resolves the binding without throwing.

      Parameters

      • env: E

        The Worker environment.

      Returns R2Bucket

      The resolved binding, or null when it is not configured.