服务端 API/消息/消息管理/获取消息中的资源文件
# 获取消息中的资源文件

获取消息中的资源文件，包括音频，视频，图片和文件，**暂不支持表情包资源下载**。当前仅支持 100M 以内的资源文件的下载。

**注意事项**：文件类型可通过 response header 中`Content-Type`字段获取

## 前提条件
调用接口前，请确保： 
- 你已为应用开启[机器人能力](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)
- 机器人和消息已在同一会话中

## 使用限制

该接口暂不支持获取合并转发消息中的子消息的资源文件。

## 请求

基本 | &nbsp;
---|---
HTTP URL | https://open.larksuite.com/open-apis/im/v1/messages/:message_id/resources/:file_key
HTTP Method | GET
接口频率限制 | [1000 次/分钟、50 次/秒](https://open.larksuite.com/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)
支持的应用类型 | Custom App、Store App
权限要求<br>**调用该 API 所需的权限。开启其中任意一项权限即可调用**<br>开启任一权限即可 | 获取与发送单聊、群组消息(im:message)<br>获取单聊、群组消息(im:message:readonly)<br>获取单聊、群组的历史消息(im:message.history:readonly)

### 请求头

名称 | 类型 | 必填 | 描述
---|---|---|---
Authorization | string | 是 | `tenant_access_token`<br>**值格式**："Bearer `access_token`"<br>**示例值**："Bearer t-7f1bcd13fc57d46bac21793a18e560"<br>[了解更多：如何选择与获取 access token](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-choose-which-type-of-token-to-use)

### 路径参数

名称 | 类型 | 描述
---|---|---
message_id | string | 待查询资源对应的消息ID。<br>**示例值**："om_dc13264520392913993dd051dba21dcf"
file_key | string | 待查询资源的key。可以调用[获取指定消息的内容](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/get)接口，通过消息ID查询消息内容中的资源Key。<br>**注意**：请求的 file_key 和 message_id 需要匹配<br>**示例值**："file_456a92d6-c6ea-4de4-ac3f-7afcf44ac78g"

### 查询参数

名称 | 类型 | 必填 | 描述
---|---|---|---
type | string | 是 | 资源类型<br>**可选值有：**<br>- `image`: 对应消息中的图片或富文本消息中的图片。<br>- `file`: 对应消息中的 文件、音频、视频（表情包除外）。<br>**示例值**：image

### 请求示例
```bash
curl --location --request GET 'https://open.larksuite.com/open-apis/im/v1/messages/om_aa0944122e2ec23545d9a93df0ceec02/resources/img_v2_98f3923d-3351-4017-8156-ee34d92196bj?type=image' \
--header 'Authorization: Bearer t-9fef198b83bfdb975f09297cf14c4a63a117c52e' 
```
```bash
curl --location --request GET 'https://open.larksuite.com/open-apis/im/v1/messages/om_4b6abce3eb423be3c2dfd11d4ca9e97b/resources/file_v2_83e69b47-5d67-4e21-bfb4-66f8bf80b7ej?type=file' \
--header 'Authorization: Bearer t-9fef198b83bfdb975f09297cf14c4a63a117c52e' 
```

## 响应

HTTP状态码为 200 时，表示成功

返回文件二进制流

### 错误码

HTTP状态码 | 错误码 | 描述 | 排查建议
---|---|---|---
400 | 230110 | Action unavailable as the message has been deleted. | 消息已经删除.
400 | 234001 | Invalid request param. | 检查请求参数是否正确。
401 | 234002 | Unauthorized. | 鉴权失败，联系Oncall解决。
400 | 234003 | File not in message. | 该资源不属于当前消息，请检查消息ID和资源Key。
400 | 234004 | App not in chat. | 应用不在消息所在的群组中，请检查消息ID是否正确。
400 | 234009 | Lack of necessary permissions. | 暂不支持在外部群中进行本操作。
400 | 234019 | scope CheckAppTenant fail. | 请重试。
400 | 234037 | Downloaded file size exceeds limit. | 不允许下载的资源大小超过100MB限制。
400 | 234038 | Do not allow downloading of message resources in restricted mode. | 不能下载保密消息中资源文件，请检查消息是否已被设置为保密，或群组开启了防泄密模式。
400 | 234040 | The message is invisible to the operator. | 该消息对操作者不可见，请联系群主或群管理员检查群设置中是否关闭了”新成员可查看历史消息“。
400 | 234041 | Tenant master key has been deleted, please contact the tenant administrator. | 租户加密密钥被删除，请联系租户管理员。
400 | 234042 | Hybrid deployment tenant storage error, such as full storage space, please contact tenant administrator. | 请求出现混布租户存储错误，如存储空间已满等，请联系租户管理员或技术支持。
400 | 234043 | Unsupported message type. | 不支持的消息类型，如合并转发消息、消息卡片。

