# 查询临时文件上传状态

用 file_key 查询上传状态。只有 state=temporary_available 的文件才能在建码或修改时以 file_key 引用；failed 按 error_code 处理，expired 需重新申请上传。

## 请求

```text
POST https://open.cli.im/api/v2/rpc/assets/getUpload
```

| 项目 | 要求 |
|---|---|
| 最低权限 | 读写，见[权限档位](https://cli.im/open-api/openapi/v2/auth.md#org-policy) |
| 需要的 scope | `assets.write` |
| 组织 Key | 不能调用，返回 403 `credential_type_not_allowed`，见[历史组织 Key](https://cli.im/open-api/openapi/v2/auth.md#org-key) |

相关调用流程：[按模板批量建码](https://cli.im/open-api/openapi/v2/scenarios/batch-create-qrcodes.md#upload)。

## 请求参数

请求体为 JSON。

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `file_key` | string | 否 | assets/requestUpload 返回的 file_key。最长 512 个字符 |
| `asset_id` | string | 否 | 旧版文件标识，仅为兼容保留；新调用请传 file_key。最长 128 个字符 |

## 请求示例

示例里的 ID、幂等键等换成实际值。

```bash
curl -sS -X POST 'https://open.cli.im/api/v2/rpc/assets/getUpload' \
  -H "Authorization: Bearer ${CAOLIAO_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
  "file_key": "free/2026/11/18/3f9a1c7e5b2d4a6c8e0f.jpg"
}'
```

## 响应

成功时 HTTP 状态码为 200，顶层 `code` 为 `0`，结果在 `data` 里。失败时的返回见[错误码与调用额度](https://cli.im/open-api/openapi/v2/error-codes.md)和[业务错误码](https://cli.im/open-api/openapi/v2/error-catalog.md)。

| 字段 | 类型 | 一定返回 | 说明 |
|---|---|---|---|
| `data.file_key` | string | 是 | 文件引用，建码和修改时填在图片、附件字段里 |
| `data.state` | string | 是 | uploading 等待上传或处理中；temporary_available 已可引用；failed 失败；expired 已过期。可选值：`uploading`、`temporary_available`、`failed`、`expired` |
| `data.expires_at` | integer | 否 | 临时文件的过期时间（Unix 秒）；被建码或修改引用并保存后转为永久文件 |
| `data.upload_expires_at` | integer | 否 | 上传地址的过期时间（Unix 秒） |
| `data.file_name` | string | 否 | 文件名 |
| `data.mime_type` | string | 否 | 文件 MIME 类型 |
| `data.size` | integer | 否 | 文件大小（字节） |
| `data.error_code` | string | 否 | state 为 failed 或 expired 时的原因码 |
| `data.upload` | object | 否 | 上传方式，state 为 uploading 且文件尚未上传时返回 |
| `data.upload.method` | string | 是 | 固定为 PUT |
| `data.upload.url` | string | 是 | 带签名的上传地址。含临时凭证，不要记录或展示 |
| `data.upload.headers` | object | 是 | 上传时必须原样带上的请求头 |

### 响应示例

```json
{
  "code": 0,
  "message": "ok",
  "data": {
    "file_key": "free/2026/11/18/3f9a1c7e5b2d4a6c8e0f.jpg",
    "state": "temporary_available",
    "file_name": "compressor.jpg",
    "mime_type": "image/jpeg",
    "size": 204800,
    "expires_at": 1795003600
  }
}
```

## 常见错误

`ASSET_NOT_FOUND`。含义和处理方式见[业务错误码](https://cli.im/open-api/openapi/v2/error-catalog.md)。

---

本页由 [openapi.json](https://cli.im/open-api/openapi/v2/overview.md#%E6%8E%A5%E5%8F%A3%E8%A7%84%E8%8C%83-openapi-json) 生成。全部接口见[接口清单](https://cli.im/open-api/openapi/v2/api-index.md)。
