分块传输模式 (PUT Object Chunked)

当客户端上传较大的对象 (Object) 时,传统传输模式需要客户端一次读取整个对象内容然后发送请求,这种情景往往是不可接受的。此时,客户端可以使用分块模式以优化上传过程。

  • Qiniu S3 API 服务分块传输模式支持任意的分块大小 (chunk size),客户端可以根据网络状态选择不同的值,推荐分块大小为 64K (bytes)。

  • Qiniu S3 API 服务即支持 RFC2616 中定义的标准分块传输模式 (Transfer-Encoding: chunked),也支持 AWS V4 中自定义的带签名分块传输模式 (Content-Encoding: aws-chunked)。

请求定义

注意:在分块传输模式请求中,客户端必须通过 X-Amz-Decoded-Content-Length 指定上传对象 (Object) 的实际大小 (bytes)!

  • 签名请求 (AWS V4 Streaming)
PUT /<BucketName>/<ObjectName> HTTP/1.1
Host: api-s3.qiniu.com
Date: <date>
Content-Encoding: aws-chunked
Content-Length: <Integer-of-Payload>
Authorization: <Your-Authenticating-String>
X-Amz-Decoded-Content-Length: <Integer-of-Object-Bytes>
X-Amz-Content-Sha256: STREAMING-AWS4-HMAC-SHA256-PAYLOAD


string(Hexadecimal(<Integer-of-Chunk-Bytes>)) + ";chunk-signature=" + Hex(HMAC-SHA256(<Chunk-Bytes>)) + "\r\n" + <Chunk-Bytes> + "\r\n" [+ ...]
  • 签名请求 (RFC2616 Transfer Encoding)
PUT /<BucketName>/<ObjectName> HTTP/1.1
Host: api-s3.qiniu.com
Date: <date>
Transfer-Encoding: chunked
Authorization: <Your-Authenticating-String>
X-Amz-Content-Sha256: Hex(HMAC-SHA256(<Your-Object-Bytes>))
X-Amz-Decoded-Content-Length: <Integer-of-Object-Bytes>


string(Hexadecimal(<Integer-of-Chunk-Bytes>)) + ";" + [<Chunk-Meta-Key=Chunk-Meta-Value> [, ...]] + "\r\n" + <Chunk-Bytes> + "\r\n" [+ ...]
  • 普通请求 (RFC2616 Transfer Encoding)
PUT /<BucketName>/<ObjectName> HTTP/1.1
Host: api-s3.qiniu.com
Date: <date>
Transfer-Encoding: chunked
Authorization: <Your-Authenticating-String>
X-Amz-Content-Sha256: UNSIGNED-PAYLOAD
X-Amz-Decoded-Content-Length: <Integer-of-Object-Bytes>


string(Hexadecimal(<Integer-of-Chunk-Bytes>)) + ";" + [<Chunk-Meta-Key=Chunk-Meta-Value> [, ...]] + "\r\n" + <Chunk-Bytes> + "\r\n" [+ ...]
请求参数

该接口未定义请求参数

请求头

请求头 (HTTP Request Header) 外,该接口定义了以下请求头:

名称 描述 要求
Content-Length 请求体长度,单位为 byte,仅针对 AWS V4 Streaming 自定义分块传输模式 CY
X-Amz-Decoded-Content-Length 上传对象的实际大小,单位为 byte Y
  • CY, 条件约束必须
  • Y, 必须
请求数据
  • 上传对象的分块 (chunk) 字节序列

响应定义

该接口未定义响应数据

  • 服务器端正确处理请求时响应 HTTP 状态码为 200

results matching ""

    No results matching ""