From 29c9fa2ef2cac7a0644ac0f6e39ccd18d410fb00 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 23 Oct 2020 11:29:51 -0700 Subject: [PATCH] byte buffer for uploading --- weed/operation/upload_content.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.go index df46627c3..5ba9e37a0 100644 --- a/weed/operation/upload_content.go +++ b/weed/operation/upload_content.go @@ -188,8 +188,9 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i } func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error, filename string, isGzipped bool, originalDataSize int, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (*UploadResult, error) { - body_buf := bytes.NewBufferString("") - body_writer := multipart.NewWriter(body_buf) + buf := bytebufferpool.Get() + defer bytebufferpool.Put(buf) + body_writer := multipart.NewWriter(buf) h := make(textproto.MIMEHeader) h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, fileNameEscaper.Replace(filename))) if mtype == "" { @@ -217,7 +218,7 @@ func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error return nil, err } - req, postErr := http.NewRequest("POST", uploadUrl, body_buf) + req, postErr := http.NewRequest("POST", uploadUrl, bytes.NewReader(buf.Bytes())) if postErr != nil { glog.V(1).Infof("create upload request %s: %v", uploadUrl, postErr) return nil, fmt.Errorf("create upload request %s: %v", uploadUrl, postErr)