await storage.run({ action: "object", key: "invoices/2026/01/a.pdf" });
// { key, size, contentType, base64: "…" }
await storage.run({ action: "object", key: "notes/today.md" });
// { key, size, contentType, text: "# Today…" }storage.run(action="object", key="invoices/2026/01/a.pdf")
# {"key", "size", "contentType", "base64": "…"}
storage.run(action="object", key="notes/today.md")
# {"key", "size", "contentType", "text": "# Today…"}text or base64
| You get | When |
|---|---|
| text | The content type is textual, or the bytes contain no null byte. |
| base64 | Anything else. |
Both fields are never present at once, so the test is which one exists.
const object = await storage.run({ action: "object", key });
const bytes = object.text !== undefined
? Buffer.from(object.text, "utf8")
: Buffer.from(object.base64, "base64");
await fs.writeFile(local, bytes);import base64
from pathlib import Path
obj = storage.run(action="object", key=key)
data = obj["text"].encode("utf-8") if "text" in obj else base64.b64decode(obj["base64"])
Path(local).write_bytes(data)The content decides, not the extension
A file named .dat holding plain text comes back as text, and that is the right answer — reading it as base64 would be a lossy round trip through an encoding it never had.
It reads the whole object
There is no range. Check size from list before fetching something large — the bytes pass through memory on both sides.
const page = await storage.run({ action: "list", prefix });
const target = page.objects.find((o) => o.key === key);
if (target.size > 25 * 1024 * 1024) throw new Error("too large to read in one call");page = storage.run(action="list", prefix=prefix)
target = next(o for o in page["objects"] if o["key"] == key)
if target["size"] > 25 * 1024 * 1024:
raise ValueError("too large to read in one call")