参数
filestring必填相对于工作空间的写入路径 。
contentstring | Buffer | Uint8Array | ArrayBuffer必填写什么 其它的都被拒绝了
文本
const item = await pc.files.write("Launch plan/brief.md", "# Brief\n\nShip in March.");
// { name: "brief.md", path: "Launch plan/brief.md", type: "file", size: 29,
// mimeType: "text/markdown", modifiedAt: "…" }item = pc.files.write("Launch plan/brief.md", "# Brief\n\nShip in March.")
# {"path": "Launch plan/brief.md", "size": 29}字符串以 UTF-8 -8 -8 -2 mimeType 返回的文件从扩展名中读取,而不是从内容中读取,所以您选择的名称是决定文件后来如何处理的名称。
二进二进
// A generated image, straight from a model session
const [picture] = await session.generate({
inputs: [{ type: "text", content: "A fox in the snow" }],
outputs: [{ type: "image" }],
}).then((r) => r.outputs);
await pc.files.write("Assets/fox.png", Buffer.from(picture.content, "base64"));
// A download
const response = await fetch("https://example.com/report.pdf");
await pc.files.write("Reports/report.pdf", await response.arrayBuffer());import base64, urllib.request
# A generated image, straight from a model session
picture = session.generate(
inputs=[{"type": "text", "content": "A fox in the snow"}],
outputs=[{"type": "image"}],
)["outputs"][0]
pc.files.write("Assets/fox.png", base64.b64decode(picture["content"]))
# A download
with urllib.request.urlopen("https://example.com/report.pdf") as response:
pc.files.write("Reports/report.pdf", response.read())它可以代替它,它一无所存,一无所存
这里没有上一个版本
平面操作 : 旧内容已经删除。 保存副本是代理商自己的写工具在. versions/ 上方添加的内容, 如果您想要在代码中出现该行为, 请先读取文件, 然后自己写出副本 。
// Keep a copy before replacing
const before = await pc.files.read("notes.md");
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
await pc.files.write(`.versions/notes.md/${stamp}.md`, before.content);
await pc.files.write("notes.md", next);from datetime import datetime, timezone
# Keep a copy before replacing
before = pc.files.read("notes.md")
stamp = datetime.now(timezone.utc).isoformat().replace(":", "-").replace(".", "-")
pc.files.write(f".versions/notes.md/{stamp}.md", before["content"])
pc.files.write("notes.md", next_content)需要时创建文件夹
写书 Clients/Acme/2026/invoice.md 沿途创建三个文件夹。 不论深度如何, 都有一个呼叫 。
错误
| 代码 | 状态 | 触发条件 |
|---|---|---|
| missing_content | 400 | content 是 undefined 或 null。空字符串是有效的。 |
| invalid_content | 400 | 不是弦,不是缓冲,不是Uint8阵列,也不是阵列。 |
| invalid_path | 400 | 绝对,在工作空间之外,或者工作空间根之外。 |
| local_files_require_node | 400 | 运行环境没有文件系统。 |
| storage_not_on_this_machine | 409 | 另一台电脑的储藏室 |
对象为 否 给您序列序列的号码: 通行证 JSON.stringify(value),所以格式 保持你的。