获取对象

最近更新时间: 2024-12-19 17:12:00

功能描述

GET Object 接口请求可以在 CSP 的存储桶中将一个文件(对象)下载至本地。该操作需要请求者对目标对象具有读权限或目标对象对所有人都开放了读权限(公有读)。

请求

请求示例

GET /<ObjectName> HTTP/1.1
Host: <BucketName-APPID>.<Endpoint>
Date: GMT Date
Authorization: Auth String

说明:

Authorization: Auth String (详细参见请求签名章节)

请求行

GET /{ObjectName} HTTP/1.1

该 API 接口接受 GET 请求。

请求参数

名称类型必选描述
response-content-typestring设置响应头部中的 Content-Type 参数
response-content-languagestring设置响应头部中的 Content-Language 参数
response-expiresstring设置响应头部中的 Content-Expires 参数
response-cache-controlstring设置响应头部中的 Cache-Control 参数
response-content-dispositionstring设置响应头部中的 Content-Disposition 参数
response-content-encodingstring设置响应头部中的 Content-Encoding 参数

请求头

公共头部

该请求操作的实现使用公共请求头,了解公共请求头详细请参见 公共请求头部 章节。

非公共头部

名称类型必选描述
RangestringRFC 2616 中定义的指定文件下载范围,以字节(bytes)为单位
If-Unmodified-Sincestring如果文件修改时间早于或等于指定时间,才返回文件内容。否则返回 412 (precondition failed)
If-Modified-Sincestring当 Object 在指定时间后被修改,则返回对应 Object meta 信息,否则返回 304(not modified)
If-Matchstring当 ETag 与指定的内容一致,才返回文件。否则返回 412 (precondition failed)
If-None-Matchstring当 ETag 与指定的内容不一致,才返回文件。否则返回 304 (not modified)

请求体

该请求请求体为空。

响应

响应头

公共响应头

该响应使用公共响应头,了解公共响应头详细请参见 公共响应头部 章节。

特有响应头

该请求操作的响应头具体数据为:

名称类型描述
x-cos-meta- *string用户自定义的元数据

响应体

下载成功,文件内容在响应体中。

错误码

错误码描述HTTP 状态码
InvalidArgument提供的参数错误400 Bad Request
SignatureDoesNotMatch提供的签名不符合规则,返回该错误码403 Forbidden
NoSuchKey如果下载的文件不存在,返回该错误码404 Not Found

实际案例

请求一

GET /123 HTTP/1.1
Host: zuhaotestnorth-1251668577.cos.ap-beijing.myqcloud.com
Date: Wed, 28 Oct 2014 22:32:00 GMT
Authorization: q-sign-algorithm=sha1&q-ak=AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&q-sign-time=1484212200;32557108200&q-key-time=1484212200;32557108200&q-header-list=host&q-url-param-list=&q-signature=11522aa3346819b7e5e841507d5b7f156f34e639

响应一

HTTP/1.1 200 OK
Date: Wed, 28 Oct 2014 22:32:00 GMT
Content-Type: application/octet-stream
Content-Length: 16087
Connection: keep-alive
Accept-Ranges: bytes
Content-Disposition: attachment; filename=\"filename.jpg\"
Content-Range: bytes 0-16086/16087
ETag: \"9a4802d5c99dafe1c04da0a8e7e166bf\"
Last-Modified: Wed, 28 Oct 2014 20:30:00 GMT
x-cos-request-id: NTg3NzQ3ZmVfYmRjMzVfMzE5N182NzczMQ==

[Object]

请求二

携带 response-xxx 参数

GET /123?response-content-type=application%2fxml HTTP/1.1
Host: zuhaotestnorth-1251668577.cos.ap-beijing.myqcloud.com
Date: Wed, 28 Oct 2014 22:32:00 GMT
Authorization: q-sign-algorithm=sha1&q-ak=AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&q-sign-time=1484212200;32557108200&q-key-time=1484212200;32557108200&q-header-list=host&q-url-param-list=&q-signature=11522aa3346819b7e5e841507d5b7f156f34e639

响应二

HTTP/1.1 200 OK
Date: Wed, 28 Oct 2014 22:32:00 GMT
Content-Type: application/xml
Content-Length: 16087
Connection: keep-alive
Accept-Ranges: bytes
Content-Disposition: attachment; filename=\"filename.jpg\"
Content-Range: bytes 0-16086/16087
ETag: \"9a4802d5c99dafe1c04da0a8e7e166bf\"
Last-Modified: Wed, 28 Oct 2014 20:30:00 GMT
x-cos-request-id: NTg3NzQ3ZmVfYmRjMzVfMzE5N182NzczMQ==

[Object]