# getStorage()

Canonical URL: https://developers.iagenify.com/pt/sdk/ref/iagenify/get-storage/
Language: pt

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

Almazage del cont predefinit, come quatro campi simples.

Status: GET /api/storage/default · free · a plain object

## Retorno {#returns}

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

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `id` | string |  | Quale tu passas come `storageId` a tutto censièrsèe. |
| `label` | string |  | Il nome display. Tua a cambiar, non a igual. |
| `type` | string |  | Que tipo di stoccaj is — vee [in basso](#types). Questo è il campo a ramificare. |
| `tier` | string |  | 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 {#types}

| tipo | Descrição | Fichiers live |
| --- | --- | --- |
| objete | Un stoccaggio d'objet: bytes sotto chiues. | Na conta |
| Base de dados | Una base di dati connessa, let e scrit a travers run(). | Na conta |
| sistema de fiches | Un computer. I suoi files sono su que la macchina. | Sull'octek, sotto ~/.iagenify/files |
| telefono | Un telefono registrato. I suoi files sono in suo browser. | In quel browser |
| Navegatore | Un 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 {#versus}

```javascript
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
```

> **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](/pt/sdk/ref/connected-storage) — l'objeto que porta `run()`, e `files` quando il storage è una máquina.

## Que la bandera predefinita decide realmente {#default}

- 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}

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

```javascript
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.
}
```

## Scrivendo a un stoccaggio nominato in lugar {#pattern}

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.

```javascript
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.
```

- [Máquinas são armazenamentos](/pt/sdk/concepts/machines-are-storages): Por que il computer che tu est en tè uno di loro.
- [api.storage](/pt/sdk/ref/storage): Conectando uno, creando uno, registrando un dispositivo.

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

```python
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
```

```python
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.
```

```python
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.
```
