# getStorage()

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

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

账户默认存储, 以四个普通字段的形式。 保存时没有目标 。

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

## 返回值 {#returns}

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

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `id` | string |  | 你所传递的, `storageId` 写作的东西。 |
| `label` | string |  | 显示名称。 您要更改, 不匹配 。 |
| `type` | string |  | 究竟是什么储藏所,你看 [下 数](#types)。这是分支的字段。 |
| `tier` | string |  | 仓库的层。 |

每个账户都是用自己的对象存储创建的, 也就是挂有默认旗帜的账户, 所以这个电话通常会用您实际可以写的东西来解答。

## 类型,以及为什么它决定了一切 {#types}

| 类型类型类型 | 说明 | 实时文件 |
| --- | --- | --- |
| 对象对象 | 对象存储: 密钥下的字节 。 | 账户中 |
| 数据库数据库数据库 | 一个通过运行读写连接的数据库( ) 。 | 账户中 |
| 文件系统 | A电脑 电脑上的文件在那台机器上 | 机上,在 ~/.iagenify/files |
| 电话电话 | 登记在册的电话 其文件在自己的浏览器里 | 浏览器 |
| 浏览器 | 浏览器商店。 | 浏览器 |

> **电脑和电话在账户上没有字节**
>
> 拒绝通过服务器保存到一个服务器 storage_is_local 而不是因为它失败了, 而是因为那些文件只存在于设备上。 从设备读取并写入它们, 透过 SDK 在那里或穿过一座桥跑

## 你可能真正想要的三件事 {#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
```

> **这不是连接的系统**
>
> 四字段,无方法。使用此调用来显示哪个存储默认值;使用 api.storage.get() 当你打算用它做点什么的时候

`api.storage.get()` 读同条路和手背a [连接连接的系统](/zh/sdk/ref/connected-storage) - 携带 `run()`, 和 `files` 当仓储是一台机器的时候。

## 默认的旗帜实际决定 {#default}

- 带无的保存 `storageId` 那边
- 这是账户的财产,不是你的客户的:换机不会改变。
- 完全由一个活性存储器携带。删除该存储器,将旗帜交给另一个,它从不留任何痕迹。
- 确实 **否** 代理商在它被赋予的设备上工作,这是另外的选择。

## 当它为无效时 {#null}

`null` 表示没有在挂着旗帜时自动保存。删除持片人手持旗帜后, a `null` 不寻常的事物 足以看 而不是重试。

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

## 写入命名存储 {#pattern}

依赖默认值对一个存储器是罚款, 几个保存器是脆弱的 : 国旗可以移动。 当一个进程必须总是写到同一个地方时, 请用标签一次性解密并保留id 。

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

- [设备即存储](/zh/sdk/concepts/machines-are-storages): 为什么电脑是你在其中之一。
- [api.storage](/zh/sdk/ref/storage): 连接一个 创建一个 登记一个装置

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