帮你快速理解、总结文档立即下载

GetObject

最近更新时间:2026-10-21 18:34:04
我的收藏
GetObject 接口请求可以将存储桶(Bucket)中的一个对象(Object)下载至本地。

注意事项

对象键末尾的 / 严格区分

对象键以 / 结尾代表目录对象,不以 / 结尾代表文件对象。两者属于不同的对象,本接口不会对对象键的末尾做任何容错。例如:
若实际只存在文件对象 foo,调用 GET /foo/ 会返回 404 NoSuchKey。
若实际只存在目录对象 foo/,调用 GET /foo 会返回 404 NoSuchKey。

目录对象

对以 / 结尾的目录对象调用 GetObject 时,行为如下:
Content-Length 固定为 0,响应体为空。
Content-Type 固定为 application/x-directory。
不返回 x-cos-hash-crc64ecma 头部。
不支持 Range 请求头部,携带时将返回 400 InvalidArgument 错误。

请求

请求语法

GET /<ObjectKey> HTTP/1.1
Host: <BucketName-APPID>.cosrapid.<Region>.myqcloud.com
Date: <GMT Date>
Authorization: <Auth String>
Range: bytes=<first>-<last> # 可选;first 或 last 可省略,如 bytes=-10、bytes=10-
说明:
Authorization 字段的具体格式见 公共请求头部。

请求参数

参数名称
描述
类型
是否必选
response-cache-control
设置响应中的 Cache-Control 头部的值
string
否
response-content-disposition
设置响应中的 Content-Disposition 头部的值
string
否
response-content-encoding
设置响应中的 Content-Encoding 头部的值
string
否
response-content-language
设置响应中的 Content-Language 头部的值
string
否
response-content-type
设置响应中的 Content-Type 头部的值
string
否
response-expires
设置响应中的 Expires 头部的值
string
否

请求头部

除 公共请求头部 外,本接口还支持以下请求头部:
Header 名称
描述
类型
是否必选
Range
RFC 2616 中定义的字节范围,仅文件对象支持。格式为 bytes=first-last,仅支持单一范围,不支持多重范围。first 与 last 均为基于 0 的偏移量,示例:bytes=0-0 表示前 1 字节、bytes=0-9 表示前 10 字节、bytes=5-9 表示第 6 到第 10 字节、bytes=-10 表示末尾 10 字节、bytes=10- 表示第 11 字节到末尾、bytes=0- 表示整个对象。指定后返回 206 Partial Content 及 Content-Range 响应头部;first 与 last 均超出对象大小时返回 416 Requested Range Not Satisfiable
string
否

请求体

该请求的请求体为空。

响应

响应头部

除 公共响应头部 外,本接口还会返回以下响应头部:
Header 名称
描述
类型
是否必返
Accept-Ranges
RFC 2616 中定义的字节范围请求支持情况,固定为 bytes
string
是
Content-Range
RFC 2616 中定义的返回内容的字节范围,仅当请求中指定了 Range 请求头部时才会返回该头部
string
否
Cache-Control
RFC 2616 中定义的缓存指令,仅当对象元数据包含此项或通过请求参数指定了此项时才会返回该头部
string
否
Content-Disposition
RFC 2616 中定义的文件名称,仅当对象元数据包含此项或通过请求参数指定了此项时才会返回该头部
string
否
Content-Encoding
RFC 2616 中定义的编码格式,仅当对象元数据包含此项或通过请求参数指定了此项时才会返回该头部
string
否
Content-Language
RFC 2616 中定义的内容语言,仅当对象元数据包含此项或通过请求参数指定了此项时才会返回该头部
string
否
Expires
RFC 2616 中定义的缓存失效时间,仅当对象元数据包含此项或通过请求参数指定了此项时才会返回该头部
string
否
x-cos-meta-*
包括用户自定义元数据头部后缀和用户自定义元数据信息
string
否
x-cos-storage-class
对象存储类型,当前固定为 RAPID
enum
是

响应体

响应体为对象的原始字节流。

错误码

本接口遵循统一的错误响应和错误码,详情请参见错误码文档。

实际案例

案例一:下载完整对象

请求

GET /exampleobject HTTP/1.1
Host: examplebucket-x--1250000000.cosrapid.ap-guangzhou.myqcloud.com
Date: Wed, 29 May 2019 04:10:12 GMT
Authorization: q-sign-algorithm=sha1&q-ak=AKIDXXXXXXXX&q-sign-time=1559074212;1559077812&q-key-time=1559074212;1559077812&q-header-list=date;host&q-url-param-list=&q-signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

响应

HTTP/1.1 200 OK
Content-Type: image/jpeg
Content-Length: 16
Connection: keep-alive
Accept-Ranges: bytes
Date: Wed, 29 May 2019 04:10:12 GMT
ETag: "ee8de918d05640145b18f70f4c3aa602"
Last-Modified: Tue, 28 May 2019 08:30:00 GMT
x-cos-storage-class: RAPID
x-cos-hash-crc64ecma: 16749565679157681890
x-cos-request-id: NjUwMDAwMDAwMDAwMDAwMDAw

[Object Content]

案例二:通过请求参数指定响应头部

请求

GET /exampleobject?response-content-type=application%2Foctet-stream&response-cache-control=max-age%3D86400&response-content-disposition=attachment%3B%20filename%3Dexample.jpg HTTP/1.1
Host: examplebucket-x--1250000000.cosrapid.ap-guangzhou.myqcloud.com
Date: Wed, 29 May 2019 04:10:12 GMT
Authorization: q-sign-algorithm=sha1&q-ak=AKIDXXXXXXXX&q-sign-time=1559074212;1559077812&q-key-time=1559074212;1559077812&q-header-list=date;host&q-url-param-list=response-cache-control;response-content-disposition;response-content-type&q-signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

响应

HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Length: 16
Connection: keep-alive
Accept-Ranges: bytes
Cache-Control: max-age=86400
Content-Disposition: attachment; filename=example.jpg
Date: Wed, 29 May 2019 04:10:12 GMT
ETag: "ee8de918d05640145b18f70f4c3aa602"
Last-Modified: Tue, 28 May 2019 08:30:00 GMT
x-cos-storage-class: RAPID
x-cos-hash-crc64ecma: 16749565679157681890
x-cos-request-id: NjUwMDAwMDAwMDAwMDAwMDAw

[Object Content]

案例三:指定 Range 请求头部下载部分内容

请求

GET /exampleobject HTTP/1.1
Host: examplebucket-x--1250000000.cosrapid.ap-guangzhou.myqcloud.com
Date: Wed, 29 May 2019 04:10:12 GMT
Range: bytes=8-14
Authorization: q-sign-algorithm=sha1&q-ak=AKIDXXXXXXXX&q-sign-time=1559074212;1559077812&q-key-time=1559074212;1559077812&q-header-list=date;host;range&q-url-param-list=&q-signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

响应

HTTP/1.1 206 Partial Content
Content-Type: image/jpeg
Content-Length: 7
Connection: keep-alive
Accept-Ranges: bytes
Content-Range: bytes 8-14/16
Date: Wed, 29 May 2019 04:10:12 GMT
ETag: "ee8de918d05640145b18f70f4c3aa602"
Last-Modified: Tue, 28 May 2019 08:30:00 GMT
x-cos-storage-class: RAPID
x-cos-hash-crc64ecma: 16749565679157681890
x-cos-request-id: NjUwMDAwMDAwMDAwMDAwMDAw

Content