Cliente

getStorage()

api.getStorage() → Promise<Storage | null>

Almazage del cont predefinit, come quatro campi simples.

GET /api/storage/defaultfreea plain object
Using Python?

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

Retorno

{
  id: "…",
  label: "Object Storage",
  type: "object",
  tier: "free"
}
{
    "id": "…",
    "label": "Object Storage",
    "type": "object",
    "tier": "free",
}
idstring

Quale tu passas come storageId a tutto censièrsèe.

labelstring

Il nome display. Tua a cambiar, non a igual.

typestring

Que tipo di stoccaj is — vee in basso. Questo è il campo a ramificare.

tierstring

L'armorzament de nivel.

Ogni conto è creato con il suo stoccaggio de objetos, e che è quello portando la bandera predefinita — quindi questo appello normalmente risponde con un lugar onde si può realmente scriver.

e por què decide tutto

tipoDescriçãoFichiers live
objeteUn stoccaggio d'objet: bytes sotto chiues.Na conta
Base de dadosUna base di dati connessa, let e scrit a travers run().Na conta
sistema de fichesUn computer. I suoi files sono su que la macchina.Sull'octek, sotto ~/.iagenify/files
telefonoUn telefono registrato. I suoi files sono in suo browser.In quel browser
NavegatoreUn negozio de browser.In quel browser
Un computer e un telefono non mantene octes sul compte

Salvare a un a través del server è negat con storage_is_local — non perché ha fallit, ma perché quei files solo existient sul dispositivo. Legga e scrie dal dispositivo, attraverso il SDK correndo là o attraverso un ponte.

Le tre cose che pots realmente desiderare

await api.getStorage();                      // the default, as plain fields

const target = await api.storage.get();      // the default, with run() and files on it
const one = await api.storage.get({ id });   // a particular storage
const all = await api.storage.list();        // every storage on the account
api.get_storage()                      # the default, as plain fields

target = api.storage.get()             # the default, with run() and files on it
one = api.storage.get(id=storage_id)   # a particular storage
every = api.storage.list()             # every storage on the account
Non è un archivio connesso

Quattro campi, senza metodi. Usare questo appello per mostrar qual storage è il predefinit; use api.storage.get() quando si intende fare algo con esso.

api.storage.get() lege la stessa rota e lee un ConnectStorage — l'objeto que porta run(), e files quando il storage è una máquina.

Que la bandera predefinita decide realmente

  • Un salvat con no storageId va là.
  • È una proprietà del conto, non del cliente: cambiare macchine non lo cambia.
  • Exactamente un stoccaggio attivo lo porta. Eliminare quel stoccaggio e il drapeau è predato a un altro — non è mai lasciato nulcun lugar.
  • Fa no decide dove lavora un agente. Un agente lavora sul dispositivo che è stato dato, e che è una scelta separata.

Quando è null

null significa che nessun storage activo porta la bandeira. Desde la cancellazione del porta-bandeira , un null è abbastanza inusual da guardare, e non retest.

const target = await api.getStorage();

if (!target) {
  const all = await api.storage.list();
  throw new Error(`no default storage; ${all.length} storage(s) on the account`);
}

if (target.type === "filesystem" || target.type === "phone") {
  // Saving here through the server will be refused: this device keeps its own files.
}
target = api.get_storage()

if target is None:
    every = api.storage.list()
    raise RuntimeError(f"no default storage; {len(every)} storage(s) on the account")

if target["type"] in ("filesystem", "phone"):
    pass  # Saving here through the server will be refused: this device keeps its own files.

Scrivendo a un stoccaggio nominato in lugar

Se basare sul predefinit è agradable per un stoccaj e fragile para varios: la bandera pode mover. Quando un processo deve sempre scriver al medesimo lugar, lo resolver con label una vez e conservar l'identit.

const all = await api.storage.list();
const archive = all.find((s) => s.label === "Archive" && s.type === "object");
if (!archive) throw new Error("the Archive storage is not connected");

// Keep archive.id in configuration, and pass it explicitly from then on.
archive = next((s for s in api.storage.list() if s.label == "Archive" and s.type == "object"), None)
if archive is None:
    raise RuntimeError("the Archive storage is not connected")

# Keep archive.id in configuration, and pass it explicitly from then on.