R2Object
Creates and manages individual objects within Cloudflare R2 Buckets.
Minimal Example
Section titled “Minimal Example”Create a text object in an R2 bucket:
import { R2Bucket, R2Object } from "alchemy/cloudflare";
const bucket = await R2Bucket("my-bucket", { name: "my-bucket",});
const textObject = await R2Object("readme", { bucket: bucket, key: "README.txt", content: "Hello, world!",});
JSON Data
Section titled “JSON Data”Store JSON configuration:
const configObject = await R2Object("config", { bucket: bucket, key: "config/app.json", content: JSON.stringify({ version: "1.0.0" }),});
Binary Data
Section titled “Binary Data”Store binary content:
const imageObject = await R2Object("avatar", { bucket: bucket, key: "images/avatar.png", content: imageBuffer, // ArrayBuffer});
Properties
Section titled “Properties”bucket
(required)
Section titled “bucket (required)”- Type:
R2Bucket
- Description: The R2 bucket where the object will be stored
key
(required)
Section titled “key (required)”- Type:
string
- Description: The object key/path within the bucket
content
(required)
Section titled “content (required)”- Type:
ReadableStream | ArrayBuffer | ArrayBufferView | string | null | Blob
- Description: The content to store in the object