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

Commit e35cc80

Browse files
committed
Fix issue #375 error uploading empty artifact
1 parent 4e9b126 commit e35cc80

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

runtime/artifact.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ func putArtifact(urlStr, mime string, stream ioext.ReadSeekCloser, additionalArt
153153
if err != nil {
154154
return errors.Wrap(err, "Failed to seek start before uploading stream")
155155
}
156+
body := ioutil.NopCloser(stream)
157+
if contentLength == 0 {
158+
// Zero is the default value for ContentLength, so if we want to avoid
159+
// using transfer-encoding: chunked, not supported by S3, we have to
160+
// specify http.NoBody when content-length is zero
161+
body = http.NoBody
162+
}
156163
req := &http.Request{
157164
Method: "PUT",
158165
URL: u,
@@ -161,13 +168,13 @@ func putArtifact(urlStr, mime string, stream ioext.ReadSeekCloser, additionalArt
161168
ProtoMinor: 1,
162169
Header: header,
163170
ContentLength: contentLength,
164-
Body: ioutil.NopCloser(stream),
171+
Body: body,
165172
GetBody: func() (io.ReadCloser, error) {
166173
// In case we have to follow any redirects, which shouldn't happen
167174
if _, serr := stream.Seek(0, io.SeekStart); serr != nil {
168175
return nil, errors.Wrap(serr, "failed to seek to start of stream")
169176
}
170-
return ioutil.NopCloser(stream), nil
177+
return body, nil
171178
},
172179
}
173180
resp, err := client.Do(req)

0 commit comments

Comments
 (0)