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…"}texto o base64
| Tú consigues | Cuándo |
|---|---|
| texto | El tipo de contenido es textual, o los bytes no contienen byte nulo. |
| base64 | Cualquier otra cosa. |
Ambos campos nunca están presentes a la vez, por lo que la prueba es cuál existe.
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)El contenido decide, no la extensión
Un archivo llamado .dat que contiene texto plano vuelve como texto, y esa es la respuesta correcta — leerlo como base64 sería un viaje de ida y vuelta con pérdidas a través de una codificación que nunca tuvo.
Lee todo el objeto
No hay rango. size desde lista antes de buscar algo grande — los bytes pasan por la memoria en ambos lados.
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")