简体   繁体   English

Go 块上传

[英]Go chunk upload

Does go support chunk upload? go 是否支持块上传? I am going to upload file as one-part multipart upload.我将上传文件作为一份分段上传。 As far as I know:我所知道的:

type Part represents a single part in a multipart body and func (*Part) Read reads the body of a part, after its headers and before the next part (if any) begins. type Part表示多部分正文中的单个部分, func (*Part) Read在其标题之后和下一部分(如果有)开始之前读取部分的正文。 I assume that Reader doesn't bother is it chunk upload or not, it just read bytes until EOF.我假设Reader不会打扰它是否上传块,它只是读取字节直到 EOF。

GoDoc 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 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)
   }

How should I handle multipart chunk upload as usual or I should adjust something?我应该如何像往常一样处理分段块上传,或者我应该调整一些东西?

The net/http client and server support chunked request bodies. net/http客户端和服务器支持分块请求体。 The client automatically uses chunked encoding when the content length is not known at the time the headers are written.当在写入标头时内容长度未知时,客户端会自动使用分块编码。 The application does not need to take any action to enable the feature.应用程序无需执行任何操作即可启用该功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM