功能描述
PUT Object 接口请求可以将本地的对象(Object)上传至指定存储桶中。该操作需要请求者对存储桶有写入权限。
细节分析
- 需要有 Bucket 的写权限。
- 如果请求头的 Content-Length 值小于实际请求体(body)中传输的数据长度,CSP 仍将成功创建文件,但 Object 大小只等于 Content-Length 中定义的大小,其他数据将被丢弃。
- 如果试图添加的 Object 的同名文件已经存在,那么新上传的文件,将覆盖原来的文件,成功时返回200 OK。
请求
请求示例
PUT /<ObjectKey> HTTP/1.1
Host: <BucketName-APPID>.<Endpoint>
Date: GMT Date
Authorization: Auth String
说明:
Authorization: Auth String (详请请参阅请求签名文档)。
请求头
公共头部
该请求操作的实现使用公共请求头,了解公共请求头详情请参阅 公共请求头部 文档。
非公共头部
该操作的实现还可以使用以下请求头。
名称 | 描述 | 类型 | 必选 |
Content-Disposition | RFC 2616 中定义的文件名称,将作为 Object 元数据保存 | string | 否 |
Content-Encoding | RFC 2616 中定义的编码格式,将作为 Object 元数据保存 | string | 否 |
Expect | 当使用 Expect:100-continue 时,在收到服务端确认后,才会发送请求内容 | string | 否 |
Expires | RFC 2616 中定义的缓存策略,将作为 Object 元数据保存 | string | 否 |
x-cos-meta-\* | 包括用户自定义头部后缀和用户自定义头部信息,将作为 Object 元数据返回,大小限制为2KB 注意:用户自定义头部信息支持下划线,但用户自定义头部后缀不支持下划线 | string | 否 |
x-cos-storage-class | 设置 Object 的存储级别,枚举值:STANDARD,STANDARD_IA,ARCHIVE。默认值:STANDARD | string | 否 |
x-cos-acl | 定义 Object 的 ACL 属性,有效值:private,public-read,default;默认值:default(继承 Bucket 权限) 注意:当前访问策略条目限制为1000条,如果您不需要进行 Object ACL 控制,请填 default 或者此项不进行设置,默认继承 Bucket 权限 | string | 否 |
x-cos-grant-read | 赋予被授权者读的权限,格式:x-cos-grant-read: id="[OwnerUin]" | String | 否 |
x-cos-grant-full-control | 赋予被授权者所有的权限,格式:x-cos-grant-full-control: id="[OwnerUin]" | String | 否 |
请求体
该请求的请求体为 Object 文件内容。
响应
响应头
公共响应头
该响应包含公共响应头,了解公共响应头详情请参阅 公共响应头部 文档。
特有响应头
该请求操作的响应头具体数据为:
名称 | 类型 | 描述 |
ETag | string | 上传文件内容的 MD5 值 |
响应体
该请求响应体为空。
错误码
该请求操作无特殊错误信息,常见的错误信息请参见 错误码 文档。
实际案例
请求
PUT /picture.jpg HTTP/1.1
Host: examplebucket-1250000000.cos.ap-beijing.myqcloud.com
Date: Wed, 28 Oct 2015 20:32:00 GMT
Authorization:q-sign-algorithm=sha1&q-ak=AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&q-sign-time=1484639384;32557535384&q-key-time=1484639384;32557535384&q-header-list=host&q-url-param-list=&q-signature=5c07b7c67d56497d9aacb1adc19963135b7d00dc
Content-Length: 64
[Object]
响应
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 0
Date: Wed,16 Aug 2017 11: 59: 33 GMT
Server: tencent-cos
x-cos-request-id: NTk5NDMzYTRfMjQ4OGY3Xzc3NGRfMWY=
使用服务端加密SSE-COS AES256
请求
PUT /object0 HTTP/1.1
Host: bucket0-1255000078.cos.chongqing.cos.****-v6-iaas.tcecloud.fsphere.cn
x-cos-server-side-encryption: AES256
x-cos-meta-md5: d41d8cd98f00b204e9800998ecf8427e
Content-Length: 0
Authorization: q-sign-algorithm=sha1&q-ak=AKID53h0z****&q-sign-time=1627895179;1627905239&q-key-time=1627895179;1627905239&q-header-list=host&q-url-param-list=&q-signature=****
响应
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 0
Date: Mon, 02 Aug 2021 09:07:19 GMT
Etag: "d41d8cd98f00b204e9800998ecf8427e"
Server: nginx
X-Cache: MISS from SZ-SQUIDWEB-81
X-Cache-Lookup: MISS from SZ-SQUIDWEB-81:8080
X-Cos-Request-Id: tx0000000000000008eb048-006107b5d8-d2f0f8-default
X-Cos-Server-Side-Encryption: AES256
X-Response-Csp-Component: proxy-raw
使用服务端加密SSE-COS SM4
请求
PUT /object0 HTTP/1.1
Host: bucket0-1255000078.cos.chongqing.cos.****-v6-iaas.tcecloud.fsphere.cn
x-cos-server-side-encryption: SM4
x-cos-meta-md5: d41d8cd98f00b204e9800998ecf8427e
Content-Length: 0
Authorization: q-sign-algorithm=sha1&q-ak=AKID53h0z****&q-sign-time=1627895179;1627905239&q-key-time=1627895179;1627905239&q-header-list=host&q-url-param-list=&q-signature=****
响应
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 0
Date: Mon, 02 Aug 2021 09:07:19 GMT
Etag: "d41d8cd98f00b204e9800998ecf8427e"
Server: nginx
X-Cache: MISS from SZ-SQUIDWEB-81
X-Cache-Lookup: MISS from SZ-SQUIDWEB-81:8080
X-Cos-Request-Id: tx000000000000000b2a5ec-00621f3560-3f0d34-default
X-Cos-Server-Side-Encryption: SM4
X-Response-Csp-Component: proxy-raw
使用服务端加密SSE-KMS AES256(使用云产品密钥)
请求
PUT /object0 HTTP/1.1
Host: bucket0-1255000078.cos.chongqing.cos.****-v6-iaas.tcecloud.fsphere.cn
x-cos-server-side-encryption: cos/kms
x-cos-meta-md5: d41d8cd98f00b204e9800998ecf8427e
Content-Length: 0
Authorization: q-sign-algorithm=sha1&q-ak=AKID****&q-sign-time=1627895711;1627905771&q-key-time=1627895711;1627905771&q-header-list=host&q-url-param-list=&q-signature=****
响应
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 0
Date: Mon, 02 Aug 2021 09:16:14 GMT
Etag: "af1713a5330ed6211480563e170b0317"
Server: nginx
X-Cache: MISS from SZ-SQUIDWEB-81
X-Cache-Lookup: MISS from SZ-SQUIDWEB-81:8080
X-Cos-Request-Id: tx0000000000000008ec55b-006107b7ee-d2f0f8-default
X-Cos-Server-Side-Encryption: cos/kms
X-Cos-Server-Side-Encryption-Cos-Kms-Key-Id: 828b44f0-d4ef-****-****-6e3f5087083f
X-Response-Csp-Component: proxy-raw
使用服务端加密SSE-KMS SM4(使用云产品密钥)
请求
PUT /object0 HTTP/1.1
Host: bucket0-1255000078.cos.chongqing.cos.****-v6-iaas.tcecloud.fsphere.cn
x-cos-server-side-encryption: cos/kms/sm4
x-cos-meta-md5: d41d8cd98f00b204e9800998ecf8427e
Content-Length: 0
Authorization: q-sign-algorithm=sha1&q-ak=AKID****&q-sign-time=1627895711;1627905771&q-key-time=1627895711;1627905771&q-header-list=host&q-url-param-list=&q-signature=****
响应
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 0
Date: Mon, 02 Aug 2021 09:16:14 GMT
Etag: "7378e9d047ad878a867d761c8334672e"
Server: nginx
X-Cache: MISS from SZ-SQUIDWEB-81
X-Cache-Lookup: MISS from SZ-SQUIDWEB-81:8080
X-Cos-Request-Id: tx000000000000000b2b518-00621f3c2e-3f0d34-default
X-Cos-Server-Side-Encryption: cos/kms/sm4
X-Cos-Server-Side-Encryption-Cos-Kms-Key-Id: 828b44f0-d4ef-****-****-6e3f5087083f
X-Response-Csp-Component: proxy-raw
使用服务端加密SSE-KMS AES256(使用用户自定义密钥)
请求
PUT /object0 HTTP/1.1
Host: bucket0-1255000078.cos.chongqing.cos.****-v6-iaas.tcecloud.fsphere.cn
x-cos-server-side-encryption: cos/kms
x-cos-server-side-encryption-cos-kms-key-id: 7addf848-eb91-****-****-6e3f5087083f
x-cos-meta-md5: d41d8cd98f00b204e9800998ecf8427e
Content-Length: 0
Authorization: q-sign-algorithm=sha1&q-ak=AKID****&q-sign-time=1627896177;1627906237&q-key-time=1627896177;1627906237&q-header-list=host&q-url-param-list=&q-signature=****
响应
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 0
Date: Mon, 02 Aug 2021 09:23:57 GMT
Etag: "bb5a92aba42f8b5657af6823024f1370"
Server: nginx
X-Cache: MISS from SZ-SQUIDWEB-81
X-Cache-Lookup: MISS from SZ-SQUIDWEB-81:8080
X-Cos-Request-Id: tx0000000000000008edac0-006107b9bd-d2f0f8-default
X-Cos-Server-Side-Encryption: cos/kms
X-Cos-Server-Side-Encryption-Cos-Kms-Key-Id: 7addf848-eb91-****-****-6e3f5087083f
X-Response-Csp-Component: proxy-raw
使用服务端加密SSE-KMS SM4(使用用户自定义密钥)
请求
PUT /object0 HTTP/1.1
Host: bucket0-1255000078.cos.chongqing.cos.****-v6-iaas.tcecloud.fsphere.cn
x-cos-server-side-encryption: cos/kms/sm4
x-cos-server-side-encryption-cos-kms-key-id: 7addf848-eb91-****-****-6e3f5087083f
x-cos-meta-md5: d41d8cd98f00b204e9800998ecf8427e
Content-Length: 0
Authorization: q-sign-algorithm=sha1&q-ak=AKID****&q-sign-time=1627896177;1627906237&q-key-time=1627896177;1627906237&q-header-list=host&q-url-param-list=&q-signature=****
响应
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 0
Date: Mon, 02 Aug 2021 09:23:57 GMT
Etag: "ed360e9f2fc4af5d2537b8172e5e11a9"
Server: nginx
X-Cache: MISS from SZ-SQUIDWEB-81
X-Cache-Lookup: MISS from SZ-SQUIDWEB-81:8080
X-Cos-Request-Id: tx000000000000000b2b8eb-00621f3df2-3f0d34-default
X-Cos-Server-Side-Encryption: cos/kms/sm4
X-Cos-Server-Side-Encryption-Cos-Kms-Key-Id: 7addf848-eb91-****-****-6e3f5087083f
X-Response-Csp-Component: proxy-raw