# readDocument()

Canonical URL: https://developers.iagenify.com/zh/sdk/ref/tools/read-document/
Language: zh

`api.tools.readDocument(sourceId) → Promise<IaGenifyFile>`

读取账户的文档中的 文档, 内容包含在内。 免费, 和相同的电话 api.files.get().

Status: GET /api/files/:id · free · content included

## 参数 {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `sourceId` | string | 必填 | 识别身份来自 [列表文档()](/zh/sdk/ref/tools/list-documents) 或从一个储蓄中。 失踪立即起降。 |

```javascript
const [first] = await api.tools.listDocuments();
const file = await api.tools.readDocument(first.id);

console.log(file.name, file.mimeType);
console.log(file.content);              // a string for text, a Buffer otherwise
```

## 回到什么 {#returns}

A 音 A [Ia 化文件](/zh/sdk/ref/files) - 同一目的 `api.files.create()` 手已经牵手,手已经牵手 `sourceId`读取,改变和放回三行

```javascript
const file = await api.tools.readDocument(id);
file.content = `${file.content}\n\nReviewed on ${new Date().toISOString().slice(0, 10)}.`;
await file.update();                    // replaces it, same sourceId
```

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `name` | string |  | 档案的名字 |
| `content` | string | Buffer |  | 文本为字符串; 其它任何文本为缓冲。 |
| `mimeType` | string |  | 保存下来的是什么 |
| `sourceId` | string |  | 已经设置 - `update()` 工作马上进行 |
| `location · metadata` | object |  | 住在哪里 记录到什么 |

## 作为一种工具,它也走一条路 {#as-a-tool}

> **一种参数,两种数值**
>
> 被宣布为模型, 其参数被称为文档, 它接受调用器计算机上的代号或路径。 先试 id; 否则, 则通过软件包在机器上读取路径 。 双方都使用一个工具, 因为模型不应该知道它持有的是什么 。

以这种方式读取的二进制文件被报告为二进制文件,而不是以混杂字符串返回——模型被告知名称、类型和大小,可以要求转换。

## 错误 {#errors}

| 代码 | 状态 | 触发条件 |
| --- | --- | --- |
| file_not_found | 404 | 此账户上没有此文件 。 |
| file_missing_on_disk | 404 | 记录在记录中,字节不在记录中。 |

打电话时没有 `sourceId` 在任何请求之前丢弃: 错误的代码, 而不是平台的回答 。

- [api.files.get()](/zh/sdk/ref/files/get): 相同调用文件资源。
- [经纪人的读](/zh/sdk/agent/tools/read): 当地代理人所看到的是什么——文件、图像、音像。
- [api.tools](/zh/sdk/ref/tools): 十五个,用它们的两个方法

```python
first = api.tools.list_documents()["account"][0]
file = api.tools.read_document(first["id"])

print(file.name, file.mime_type)
print(file.content)              # a str for text, bytes otherwise
```

```python
from datetime import date

file = api.tools.read_document(source_id)
file.content = f"{file.content}\n\nReviewed on {date.today().isoformat()}."
file.update()                    # replaces it, same source_id
```
