运行 $ 写

上传

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

将字节放在键下。文字不变,其他的则作为基数64——这种区分不是可选的。

object storagefreereplaces without warning
Using Python?

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

参数

keystring必填

鞭子是字符,不是文件夹

contentstring

文本内容, 按原样发送 。

contentBase64string

任何二进制的东西 以字节64为基数

contentTypestring

值得考虑——它决定读者如何看待它。

// 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}
当文本到达时发送的二进制已损坏

缓冲字符串通过文本编码,该编码无法通过任意字节生存。上传成功和文件被打破——这是最糟糕的失败,因为没有报告。

以无要求取代

现有密钥被覆盖, 回复与新写一样。 没有前一版本 。

// 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)

在第一个写入前设计密钥

  • 鞭笞使前置置置件,而前置置件是唯一的物体存储分组。
  • 将您要过滤的东西放在左边: invoices/2026/01/ 列出一个月; 01/2026/invoices/ 没有。
  • 键在稍后很难更改——重命名是复制和删除,一个对象一次。

空间满时拒绝

quota_exceeded,在发送字节之前检查。 使用 之前,一个大宗进口比发现中途路程便宜。