Parâmetros
storageIdstringA qual stoccatura scriver. Senza di essa, il default del conto.
pathstringNodesolo. Scrive anche i bytes a questo percorso local, creando i folders.
localOnlybooleanCon path: scrive localmente e stop. Nada è caricato, niente è caricato.
Tres modos d'utilitîla
// 1. To the account — the usual one
await file.save();
// 2. To the account AND to this machine, in one call
await file.save({ path: "./out/report.md" });
// 3. To this machine only — no request, no credit
await file.save({ path: "./out/report.md", localOnly: true });
// { ok: true, status: "saved_local", path: "./out/report.md" }# 1. To the account — the usual one
file.save()
# 2. To the account AND to this machine, in one call
file.save(path="./out/report.md")
# 3. To this machine only — no request, no credit
file.save(path="./out/report.md", local_only=True)
# {"ok": True, "status": "saved_local", "path": "./out/report.md"}Se il percorso non puèr scrivi, il SDK advertiu la console e prosegui al upload. Controla il file tu stesso quando la copia locale è quella che importa — un dossier solo di lettura non va sollevare.
Retorno
{
ok: true,
status: "saved",
sourceId: "…", // how you find it again
name: "report.md",
category: "document",
mimeType: "text/markdown",
location: "object", // the kind of storage it landed in
metadata: {
size: 2048,
storageId: "…",
remainingBytes: null, // what is left, when the storage tracks it
durationMs: 260
},
creditsUsed: 1
}{
"ok": True,
"status": "saved",
"sourceId": "…", # how you find it again
"name": "report.md",
"category": "document",
"mimeType": "text/markdown",
"location": "object", # the kind of storage it landed in
"metadata": {
"size": 2048,
"storageId": "…",
"remainingBytes": None, # what is left, when the storage tracks it
"durationMs": 260,
},
"creditsUsed": 1,
}L'ogget impara da lui: file.sourceId, file.location e file.metadata sono set, che è ciò che rende update()pozibil drept.
Scelse a dove va
// The account's default
await file.save();
// A storage you named
const all = await api.storage.list();
const archive = all.find((s) => s.label === "Archive");
await file.save({ storageId: archive.id });# The account's default
file.save()
# A storage you named
archive = next(s for s in api.storage.list() if s.label == "Archive")
file.save(storage_id=archive.id)| Tipo di stoccaggio | Salve a lui |
|---|---|
| Objeto · base de données | si — bytes sono mantenuti a s'accusa |
| sistema de fiches (un computer) | Refusat: storage_is_local |
| Telefono · Navegador | Refusat: storage_is_local |
Il rejet viene ante il credito è spendet. Non è un obliguât di riprovare: quei dispositivi mantene i propri files, e la forma di scrii-li è dal dispositivo.
Il credito, e quando torna
- Un credito è preso prima de la scrittura.
- Se la scrittura poi failed, è refinançât in full e si obteve
502 storage_failed. - Un renegazione che prima occasiona — ni stoccatura, ni local, ni content — non costa nulla.
Un documente continua a ser lavorat sul dopo che si obten la risposta
Quando la categoria è document, il testo è indexat per la ricerca semantica una volta che la risposta è inviata. Quindi un file è immediatamente leggibile e reperibile-mediante-significati un moment dopo.
Indiczation non è deliberatamente atteso — mantiene la salvata veloci. Una ricerca in seguida puè non vedr.
Erros
| Código | Status | Quando | Crédito |
|---|---|---|---|
| — (erro lançado localmente) | — | il contenuto non è definito o null. | non è preso |
| missing_file_content | 400 | Ni un file ni un contenit textuèt arrivè al server. | non è preso |
| storage_not_found | 404 | Il cont non has stoccat dumnum. | non è preso |
| storage_is_local | 400 | L'obiettivo è un computer o un telefono. | non è preso |
| not_enough_credits | 402 | Il saldo non lo coprirà. | non è preso |
| storage_failed | 502 | La scrittura stessa ha fallit. | restituito |
import { IaGenifyError } from "iagenify";
try {
await file.save({ storageId });
} catch (err) {
if (err instanceof IaGenifyError && err.code === "storage_is_local") {
// That storage is a device. Write it there instead.
const device = await api.storage.get({ id: storageId });
await device.files.write("report.md", file.content);
} else throw err;
}from iagenify import IaGenifyError
try:
file.save(storage_id=storage_id)
except IaGenifyError as error:
if error.code != "storage_is_local":
raise
# That storage is a device. Write it there instead.
device = api.storage.get(id=storage_id)
device.files.write("report.md", file.content)