diff --git a/post-processor/vagrant-cloud/client.go b/post-processor/vagrant-cloud/client.go index 0c475075d..a66d3eb4a 100644 --- a/post-processor/vagrant-cloud/client.go +++ b/post-processor/vagrant-cloud/client.go @@ -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) } - defer file.Close() - - body := &bytes.Buffer{} - - _, err = io.Copy(body, file) + fi, err := file.Stat() 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 { 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) + request.ContentLength = fi.Size() resp, err := v.client.Do(request) log.Printf("Post-Processor Vagrant Cloud Upload Response: \n\n%+v", resp)