去块上传

问题描述

是否支持上传? 我将文件上传为一部分。 据我所知:

type Part表示多部分主体中的单个部分,func (*Part) Read在其标题之后和下一部分(如果有)开始之前读取该部分的主体。 我假设Reader不会干扰是否上传块,它只会读取字节直到EOF。

GoDoc

type Part struct {

    // r is either a reader directly reading from mr,or it's a
    // wrapper around such a reader,decoding the
    // Content-transfer-encoding
    r io.Reader

GoDoc

   // If Body is present,Content-Length is <= 0 and TransferEncoding
   // hasn't been set to "identity",Write adds "transfer-encoding:
   // chunked" to the header. Body is closed after it is sent.
   func (r *Request) Write(w io.Writer) error {
        return r.write(w,false,nil,nil)
   }

我应该像往常一样处理分段上传吗?还是应该进行一些调整?

解决方法

net/http客户端和服务器支持分块的请求正文。当写入标头时内容长度未知时,客户端会自动使用分块编码。该应用程序无需采取任何措施即可启用该功能。