From a1747c21f73b0438690ed17b9bde6e6a936bbd2d Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Mon, 12 Jun 2017 11:07:33 -0700 Subject: [PATCH 1/2] vagrant-cloud: use less memory when uploading --- post-processor/vagrant-cloud/client.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/post-processor/vagrant-cloud/client.go b/post-processor/vagrant-cloud/client.go index 0c475075d..a3df938e6 100644 --- a/post-processor/vagrant-cloud/client.go +++ b/post-processor/vagrant-cloud/client.go @@ -110,15 +110,7 @@ func (v VagrantCloudClient) Upload(path string, url string) (*http.Response, err defer file.Close() - body := &bytes.Buffer{} - - _, err = io.Copy(body, file) - - if err != nil { - return nil, fmt.Errorf("Error uploading file: %s", err) - } - - request, err := http.NewRequest("PUT", url, body) + request, err := http.NewRequest("PUT", url, file) if err != nil { return nil, fmt.Errorf("Error preparing upload request: %s", err) From 519256feb0e7a81a495089b305908fd1ea20c066 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Mon, 12 Jun 2017 15:01:19 -0700 Subject: [PATCH 2/2] add content-length to file upload --- post-processor/vagrant-cloud/client.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/post-processor/vagrant-cloud/client.go b/post-processor/vagrant-cloud/client.go index a3df938e6..a66d3eb4a 100644 --- a/post-processor/vagrant-cloud/client.go +++ b/post-processor/vagrant-cloud/client.go @@ -108,6 +108,12 @@ func (v VagrantCloudClient) Upload(path string, url string) (*http.Response, err return nil, fmt.Errorf("Error opening file for upload: %s", err) } + fi, err := file.Stat() + + if err != nil { + return nil, fmt.Errorf("Error stating file for upload: %s", err) + } + defer file.Close() request, err := http.NewRequest("PUT", url, file) @@ -118,6 +124,7 @@ func (v VagrantCloudClient) Upload(path string, url string) (*http.Response, err log.Printf("Post-Processor Vagrant Cloud API Upload: %s %s", path, url) + request.ContentLength = fi.Size() resp, err := v.client.Do(request) log.Printf("Post-Processor Vagrant Cloud Upload Response: \n\n%+v", resp)