api.files

file.update()

file.update() → Promise<Result>

替换已保存文件的内容。不需要任何参数:它现在发送对象上的内容。

PUT /api/files/:idfreeneeds a sourceId
Using Python?

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

不寻常的部分是它读的是对象,而不是其论点。 file.content调,调 update(),这就是新的内容。

const file = await api.files.get(sourceId);

file.content = "# Q4\n\nRevised after the audit.";
await file.update();
file = api.files.get(source_id)

file.content = "# Q4\n\nRevised after the audit."
file.update()

需要的东西

条件条件否则
file.sourceId 设置排 SDK 扔弃:没有要更新的
file.content 并非空排 SDK 扔弃:空文件不是内容

两者在提出要求之前都被扔到当地。 sourceId 调自 (c) () 获得或获得它 (已) 自然序列运作 新鲜 create()d 对象没有。

const file = api.files.create({ name: "notes.md", content: "…" });
await file.update();   // throws — never saved, so no sourceId

await file.save();     // now it has one
file.content = "…";
await file.update();   // fine
file = api.files.create(name="notes.md", content="…")
file.update()   # raises ValueError — never saved, so no source_id

file.save()     # now it has one
file.content = "…"
file.update()   # fine

返回值

{
  ok: true,
  message: "…",
  sourceId: "…",
  metadata: { size: 2048, mimeType: "text/markdown" }
}
{
    "ok": True,
    "message": "…",
    "sourceId": "…",
    "metadata": {"size": 2048, "mimeType": "text/markdown"},
}

替换,不附加

新内容是整个内容。 要添加到文件、 读取、 连接和更新 。

const file = await api.files.get(sourceId);
file.content = `${file.content}\n${newLine}`;
await file.update();
file = api.files.get(source_id)
file.content = f"{file.content}\n{new_line}"
file.update()
没有上一个版本

旧内容已经删除。 如果重要的话, 先读取它—— 读取是免费的。 历史重要文件需要每个版本的新文件, 而不是更新 。

事物不变,

变动未修改
内容及其大小名称名称
仓库剩余空间MIMEType, 所以分类
源Id

因此文本文件不能通过更新而成为图像。 另存一个新的文本文件 。

可搜索文字没有重新索引

语义搜索仍然来自旧文本的答案

保存时会使用索引。更新后,搜索可以返回您替换的版本。如果重要,删除并保存,而不是更新。

错误

代码状态触发条件
—(在本地抛出)—没有源Id, 也没有内容 。
file_not_found404此账户没有此id 的文档 。
missing_content400没有可用的设备到达服务器 。