# list()

Canonical URL: https://developers.iagenify.com/zh/sdk/ref/files/list/
Language: zh

`api.files.list() → Promise<File[]>`

账户上的每一文件,作为简单记录,没有内容,没有电话大小限制——这是库存。

Status: GET /api/files · free · an array

## 返回值 {#returns}

```javascript
[
  {
    id: "…",
    name: "report.md",
    category: "document",
    mimeType: "text/markdown",
    size: 2048,
    storageId: "…",
    status: "done",
    createdAt: "2026-10-07T11:02:08.400Z"
  }
]
```

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `id` | string |  | 什麽 [(c) () 获得](/zh/sdk/ref/files/get), `update()` 和 `delete()` 拿着 |
| `name` | string |  | 如你所命名的 |
| `category` | string |  | `image` · `data` · `document` · `video` · `audio`. |
| `mimeType` | string |  | 保存的类型 。 |
| `size` | integer |  | 字节。 在获取大东西之前先读读这个 。 |
| `storageId` | string |  | 哪个仓库有它。 |
| `status` | string |  | `done` 当它在那里的时候。 |
| `createdAt` | string |  | 保存时 |

直直- 直接- 而不是信封 。 内容不在它的内容中 : 无论您有多少文件, 此调用仍然便宜, 读取一个 [(c) () 获得](/zh/sdk/ref/files/get).

## 全部都还回来 {#everything}

没有限制,也没有光标, 因此一个有成千上万个文件的账户 以千个文件回答。 过滤器和排序在您一边 。

```javascript
const files = await api.files.list();

// What is actually taking the space
const heaviest = [...files].sort((a, b) => b.size - a.size).slice(0, 10);

// How much, in total and per storage
const total = files.reduce((sum, f) => sum + (f.size || 0), 0);

const perStorage = new Map();
for (const f of files) {
  perStorage.set(f.storageId, (perStorage.get(f.storageId) || 0) + (f.size || 0));
}
```

## 选一个读 {#picking}

```javascript
const files = await api.files.list();

const latest = files
  .filter((f) => f.category === "document")
  .sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt))[0];

const file = await api.files.get(latest.id);
```

> **名称不唯一**
>
> 以一个名字保存两次后, 就会有两个文件 。 匹配 id, 并且将这个名字当作人们的标签 。

## 安全运行的清理 {#tidy}

```javascript
const files = await api.files.list();
const month = Date.now() - 30 * 24 * 60 * 60 * 1000;

const temporary = files.filter(
  (f) => f.name.startsWith("tmp-") && Date.parse(f.createdAt) < month,
);

for (const f of temporary) await api.files.delete(f.id);
```

由你控制的东西所窄, 而不是仅按年龄来写, 年龄并不是文件完成的信号。

- [get()](/zh/sdk/ref/files/get): 阅读一,内容。
- [delete()](/zh/sdk/ref/files/delete): 正在删除一个。

```python
[
    {
        "id": "…",
        "name": "report.md",
        "category": "document",
        "mimeType": "text/markdown",
        "size": 2048,
        "storageId": "…",
        "status": "done",
        "createdAt": "2026-10-07T11:02:08.400Z",
    }
]
```

```python
from collections import Counter

files = api.files.list()

# What is actually taking the space
heaviest = sorted(files, key=lambda f: f.get("size") or 0, reverse=True)[:10]

# How much, in total and per storage
total = sum(f.get("size") or 0 for f in files)

per_storage = Counter()
for f in files:
    per_storage[f["storageId"]] += f.get("size") or 0
```

```python
files = api.files.list()

latest = max((f for f in files if f["category"] == "document"), key=lambda f: f["createdAt"])

file = api.files.get(latest["id"])
```

```python
from datetime import datetime, timedelta, timezone

files = api.files.list()
month = datetime.now(timezone.utc) - timedelta(days=30)

temporary = [f for f in files
             if f["name"].startswith("tmp-")
             and datetime.fromisoformat(f["createdAt"].replace("Z", "+00:00")) < month]

for f in temporary:
    api.files.delete(f["id"])
```
