Skip to content

指南

创建 bucket

上手POST /v1/accounts/{accountId}/r2/buckets。不提供 Cloudflare REST。

Worker 读写

ts
await env.BUCKET.put("notes/1.txt", "hello", {
  httpMetadata: { contentType: "text/plain" },
});
const hit = await env.BUCKET.get("notes/1.txt");
const listed = await env.BUCKET.list({ prefix: "notes/" });
await env.BUCKET.delete("notes/1.txt");

完整选项见 R2 Workers API

S3-compatible

对象字节在配置的 provider 上。可以用该 provider 的 S3 SDK 操作同一 prefix。那不是 Cloudflare R2 REST,也不走 Worker binding。Worker 路径才是与 Cloudflare 对齐的 API。