From 3e90b7c1fa872e3c211eb2187887a1f31766c8e3 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 13 Jan 2011 09:59:49 -0800 Subject: [PATCH] Send a Content-Length on Go client's upload. --- lib/go/client/upload.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/go/client/upload.go b/lib/go/client/upload.go index 7bec44865..4b6b8c2e4 100644 --- a/lib/go/client/upload.go +++ b/lib/go/client/upload.go @@ -106,18 +106,26 @@ func (c *Client) Upload(h *UploadHandle) (*PutResult, os.Error) { } } + // TODO: use a proper random boundary boundary := "sdf8sd8f7s9df9s7df9sd7sdf9s879vs7d8v7sd8v7sd8v" - req = http.NewPostRequest(uploadUrl, - "multipart/form-data; boundary="+boundary, - io.MultiReader( - strings.NewReader(fmt.Sprintf( + + multiPartHeader := fmt.Sprintf( "--%s\r\nContent-Type: application/octet-stream\r\n" + "Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\n\r\n", boundary, - h.BlobRef, h.BlobRef)), + h.BlobRef, h.BlobRef) + multiPartFooter := "\r\n--"+boundary+"--\r\n" + + log.Printf("Uploading to URL: %s", uploadUrl) + req = http.NewPostRequest(uploadUrl, + "multipart/form-data; boundary="+boundary, + io.MultiReader( + strings.NewReader(multiPartHeader), h.Contents, - strings.NewReader("\r\n--"+boundary+"--\r\n"))) + strings.NewReader(multiPartFooter))) req.Header["Authorization"] = authHeader + req.ContentLength = int64(len(multiPartHeader)) + h.Size + int64(len(multiPartFooter)) + req.TransferEncoding = nil resp, err = req.Send() if err != nil { return error("upload http error", err)