参数
namestring文件名。 账户上使用的原样; 服务器将它降为自有磁盘上的安全文件 。
contentstring|Buffer|Blob字节。 可以在建筑后设置 - 读取于 save()而不是在这里
mimeTypestring默认默认为 application/octet-stream类别,即类别 document.
它同步返回,没有 await:这是一个建筑师,名称除外。
对象
const file = api.files.create({ name: "notes.md", content: "…", mimeType: "text/markdown" });
file.name;
file.content;
file.mimeType;
file.sourceId; // null until it is saved
file.location; // null until it is saved
file.metadata; // null until it is savedfile = api.files.create(name="notes.md", content="…", mime_type="text/markdown")
file.name
file.content
file.mime_type
file.source_id # None until it is saved
file.location # None until it is saved
file.metadata # None until it is saved设置 MIMET 类型, 即使它是可选的
它可以决定两件事 以后改变是尴尬的 类别,以及是否 get() 内容作为文本或字节以文字或字节形式重新掌起。
| 你过 | 类别 | 返回 () 返回 |
|---|---|---|
| 文字文字文字文字/markdown | 文档文档文档文档 | 字符串内容内容 |
| 应用/json | 数据数据数据数据数据 | 字符串内容内容 |
| 图像图像图像图像/png | 图像图像图像图像 | 内装为缓冲 |
| (无) | 文档文档文档文档 | 内装为缓冲 |
离开它,文字就会以字节的形式回来
没有类型, 默认是一个二进制文件, 所以一个完全可读的 Markdown 文件会以缓存形式被交还。 现在有一条工作线, 或者稍后会读错 。
接受内容
// A string
api.files.create({ name: "notes.md", content: "# Notes", mimeType: "text/markdown" });
// Bytes you already have
api.files.create({ name: "chart.png", content: pngBuffer, mimeType: "image/png" });
// Something generated — write it out the moment you have it
const { outputs } = await assistant.generate({ inputs, outputs: [{ type: "image" }] });
api.files.create({ name: "cover.png", content: outputs[0].content, mimeType: outputs[0].mime });import base64
# A string
api.files.create(name="notes.md", content="# Notes", mime_type="text/markdown")
# Bytes you already have
api.files.create(name="chart.png", content=png_bytes, mime_type="image/png")
# Something generated — write it out the moment you have it
outputs = assistant.generate(inputs=inputs, outputs=[{"type": "image"}])["outputs"]
api.files.create(name="cover.png", content=base64.b64decode(outputs[0]["content"]), mime_type=outputs[0].get("mime"))之后填填
保存时内容会读取, 所以先构建对象, 然后再填充它是好的, 并且它是如何 update() 工作。
const file = api.files.create({ name: "log.txt", mimeType: "text/plain" });
file.content = lines.join("\n");
await file.save();
// And to replace it later
file.content = "…";
await file.update();file = api.files.create(name="log.txt", content="", mime_type="text/plain")
file.content = "\n".join(lines)
file.save()
# And to replace it later
file.content = "…"
file.update()本地拒绝保存无内容的保存
下 SDK 当内容未定义或无效时, 将丢弃在任何请求之前—— 空字符串则是一个合法的空文件 。