下载文件
更新时间:2026-11-24
接口说明
- 本接口用于下载账号下的一个文件,响应为文件流。
- Content-Type 固定为 application/octet-stream,Content-Disposition 为 attachment。
- 文件不存在或不属于当前账号时返回 404 FileNotFound。
请求结构
Plain Text
1POST /v1/agents/files/download HTTP/1.1
2Host: aw-harness.bj.baidubce.com
3Authorization: authorization string
4Content-Type: application/json
5
6{
7 "fileId": "file-a1b2c3d4"
8}
请求头域
除公共头域外,无其它特殊头域。
请求参数
| 参数名称 | 类型 | 是否必需 | 参数位置 | 描述 |
|---|---|---|---|---|
| fileId | String | 是 | RequestBody参数 | 文件 ID。 |
返回头域
| 响应头 | 描述 |
|---|---|
| Content-Type | 固定为 application/octet-stream。 |
| Content-Disposition | 固定为 attachment,携带文件名。 |
返回参数
响应体为文件的二进制内容,无 JSON 结构。
错误码
| 错误码 | 错误描述 | HTTP状态码 | 中文解释 |
|---|---|---|---|
| InvalidArgument | The request parameters are invalid. | 400 | fileId 缺失或请求体含未识别字段。 |
| Forbidden | Operation requires an admin caller. | 403 | 缺少鉴权账号或跨账号访问他人资源。 |
| FileNotFound | File not found. | 404 | 文件不存在或不属于当前账号。 |
| PersistFailed | Failed to read the file. | 500 | 服务端存储读取失败,可重试。 |
| Internal | Internal server error. | 500 | 服务端内部错误,保留 requestId 联系维护方。 |
请求示例
Plain Text
1curl -X POST http://aw-harness.bj.baidubce.com/v1/agents/files/download \
2 -H "Host: aw-harness.bj.baidubce.com" \
3 -H "Authorization: bce-auth-v1/f81d3b34e48048fbb2634dc7882d7e21/2015-08-11T04:17:29Z/3600/host/74c506f68c65e26c633bfa104c863fffac5190fdec1ec24b7c03eb5d67d2e1de" \
4 -H "Content-Type: application/json" \
5 -d '{"fileId": "file-a1b2c3d4"}' \
6 --output report.pdf
返回示例
Plain Text
1HTTP/1.1 200 OK
2Content-Type: application/octet-stream
3Content-Disposition: attachment; filename="report.pdf"
4x-bce-request-id: 9f3d0e6a-1c2b-4d5e-8a7f-0b1c2d3e4f5a
5Server: BWS
6
7<文件二进制内容>
评价此篇文章
