corse · scriver

upload

storage.run({ action: "upload", key, content | contentBase64, contentType })

Metìs bytes sotto una chiave. Texto tal qualquondo, ninguna altra cosa como base64 — e que la distinzion non è optativa.

object storagefreereplaces without warning
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Parâmetros

keystringobrigatório

Le slashes sono caracteres, non cartelle.

contentstring

Contenuto di testo, inviato come è.

contentBase64string

Qualquer cosa binaria. Base64 dei bytes.

contentTypestring

Quale è. Vale la pena impostare — decide come un lector lo tratta.

// Text
await storage.run({ action: "upload", key: "notes/today.md",
  content: "# Today\n\n…", contentType: "text/markdown" });

// Binary — base64, always
await storage.run({ action: "upload", key: "invoices/2026/01/a.pdf",
  contentBase64: pdfBuffer.toString("base64"), contentType: "application/pdf" });
// { ok: true, key: "invoices/2026/01/a.pdf", size: 183204 }
import base64

# Text
storage.run(action="upload", key="notes/today.md",
            content="# Today\n\n…", contentType="text/markdown")

# Binary — base64, always
storage.run(action="upload", key="invoices/2026/01/a.pdf",
            contentBase64=base64.b64encode(pdf_bytes).decode(), contentType="application/pdf")
# {"ok": True, "key": "invoices/2026/01/a.pdf", "size": 183204}
Binario inviat come text arriva corros

Un buffer secratificat passa attraverso una codificatura di testo che non sopravà a octets arbitrari. Il upload succede e il file è rotto — che è la pire specie de fallimento, perché nulla lo informa.

Se substitue sine chiedere

Una chiave existente è sovrascrit e la risposta è igual a una scrittura fresca. Non vi è una versione anterior.

// Check first, if replacing would be wrong
const page = await storage.run({ action: "list", prefix: key });
if ((page.objects || []).some((o) => o.key === key)) {
  throw new Error(`${key} already exists`);
}

await storage.run({ action: "upload", key, contentBase64, contentType });
# Check first, if replacing would be wrong
page = storage.run(action="list", prefix=key)
if any(o["key"] == key for o in page.get("objects") or []):
    raise FileExistsError(f"{key} already exists")

storage.run(action="upload", key=key, contentBase64=content_base64, contentType=content_type)

Disegna la chiave prima di scriver

  • Prefixi di slashes e prefixi sono i soli raggrupament di un storage d'objets ha.
  • Metîe quello che filtrare da a sinistra: invoices/2026/01/ listes un mese; 01/2026/invoices/ non lo fa.
  • Le teclas sono difficult a cambiare più tard — renominare è una copia e un elimina, un objeto a la volta.

Refuse quando lo spazio è pieno

quota_exceeded, verificat prima che i bytes siano inviati. usage, prima che un'importazione grande sia più barata di trovare la mitjana.