La forma è inusual e vale una frase: create() non fa ningun lugar. Ti da un oggetto che riempie, e save() è lo che raggiunge il server. Quella separazion è lo que lascia il medesimo objete ser scrit al disco, al conto, o a ambos.
La superficie
| Chamada | Função | Custos |
|---|---|---|
| api.files.create({ name, content, mimeType }) | Construe un objete de file. | niente |
| file.save({ storageId, path, localOnly }) | Lo scrie — al cont, al disco, o a ambos. | 1 credito |
| file.update() | Sostitue il conteniu di un ya salvat. | niente |
| api.files.get(sourceId) | Lee un retro, contenuto incluso. | niente |
| api.files.list() | Cada file del cont. | niente |
| api.files.delete(sourceId) | Lo remove, e lo che era indexat de lui. | niente |
Fine a fin
// 1. Build it — nothing has happened yet
const file = api.files.create({
name: "report.md",
content: "# Q4\n\nRevenue was…",
mimeType: "text/markdown",
});
// 2. Save it — this is the call that spends
const saved = await file.save();
saved.sourceId; // how you will find it again
file.sourceId; // the object learned its own id
// 3. Read it back, anywhere
const again = await api.files.get(saved.sourceId);
again.content; // "# Q4\n\nRevenue was…"
// 4. Replace its content
again.content = "# Q4\n\nRevised.";
await again.update();
// 5. Remove it
await api.files.delete(saved.sourceId);# 1. Build it — nothing has happened yet
file = api.files.create(
name="report.md",
content="# Q4\n\nRevenue was…",
mime_type="text/markdown",
)
# 2. Save it — this is the call that spends
saved = file.save()
saved["sourceId"] # how you will find it again
file.source_id # the object learned its own id
# 3. Read it back, anywhere
again = api.files.get(saved["sourceId"])
again.content # "# Q4\n\nRevenue was…"
# 4. Replace its content
again.content = "# Q4\n\nRevised."
again.update()
# 5. Remove it
api.files.delete(saved["sourceId"])Onde va un file
Al storage predefinito del cont, a meno che non si nomine un altro con storageId. Un tipo di storage non può tomî-lo.
Salvare a un a través del server è negato con storage_is_local, prima di ogni credito è gasta — non un fallo, un'indicazione: quei bytes vivon su quel dispositivo. Legga e scrie-le dal dispositivo stesso.
Che significa api.files è para i files de la conta. Per i propri files de la machina, ved LocalFiles; para i contenuti de un storage de objetos, storage.run().
La categoria è dedut, non dichiara
| Tipomime | categoria |
|---|---|
| Imagem/* | Imagem |
| audio/* | audio |
| video/* | video |
| Json · yaml · xml · csv | Dati |
| ningun altro | document |
Importa per un motivo: un document è indexat per la ricerca semantica dopo che è salvat, quindi si può trovare per significat posteriore.
Due cose vale la pena sapere prima di edificar su
- Costuis de salvament un credit, rimborsat integralmente se la scrittura non fa. Lectura, lista e cancellazione non costa nulla.
- L'oggetto de file è un manico che tu riempis.
create()nunca tocca la rete, quindi una superficie de erros de validazione asave().