Merge pull request #5005 from hashicorp/fix5004

vagrant-cloud: use less memory when uploading
This commit is contained in:
Matthew Hooker 2017-06-12 17:36:31 -07:00 committed by GitHub
commit 207eaaef7e
1 changed files with 6 additions and 7 deletions

View File

@ -108,17 +108,15 @@ func (v VagrantCloudClient) Upload(path string, url string) (*http.Response, err
return nil, fmt.Errorf("Error opening file for upload: %s", err) return nil, fmt.Errorf("Error opening file for upload: %s", err)
} }
defer file.Close() fi, err := file.Stat()
body := &bytes.Buffer{}
_, err = io.Copy(body, file)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error uploading file: %s", err) return nil, fmt.Errorf("Error stating file for upload: %s", err)
} }
request, err := http.NewRequest("PUT", url, body) defer file.Close()
request, err := http.NewRequest("PUT", url, file)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error preparing upload request: %s", err) return nil, fmt.Errorf("Error preparing upload request: %s", err)
@ -126,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) log.Printf("Post-Processor Vagrant Cloud API Upload: %s %s", path, url)
request.ContentLength = fi.Size()
resp, err := v.client.Do(request) resp, err := v.client.Do(request)
log.Printf("Post-Processor Vagrant Cloud Upload Response: \n\n%+v", resp) log.Printf("Post-Processor Vagrant Cloud Upload Response: \n\n%+v", resp)