Skip to content
This repository has been archived by the owner on Feb 27, 2020. It is now read-only.

Commit

Permalink
Fix issue #375 error uploading empty artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasfj committed Apr 29, 2018
1 parent 3902012 commit 57ccd6f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions runtime/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ func putArtifact(urlStr, mime string, stream ioext.ReadSeekCloser, additionalArt
if err != nil {
return errors.Wrap(err, "Failed to seek start before uploading stream")
}
body := ioutil.NopCloser(stream)
if contentLength == 0 {
// Zero is the default value for ContentLength, so if we want to avoid
// using transfer-encoding: chunked, not supported by S3, we have to
// specify http.NoBody when content-length is zero
body = http.NoBody
}
req := &http.Request{
Method: "PUT",
URL: u,
Expand All @@ -161,13 +168,13 @@ func putArtifact(urlStr, mime string, stream ioext.ReadSeekCloser, additionalArt
ProtoMinor: 1,
Header: header,
ContentLength: contentLength,
Body: ioutil.NopCloser(stream),
Body: body,
GetBody: func() (io.ReadCloser, error) {
// In case we have to follow any redirects, which shouldn't happen
if _, serr := stream.Seek(0, io.SeekStart); serr != nil {
return nil, errors.Wrap(serr, "failed to seek to start of stream")
}
return ioutil.NopCloser(stream), nil
return body, nil
},
}
resp, err := client.Do(req)
Expand Down

0 comments on commit 57ccd6f

Please sign in to comment.