Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit d86f958

Browse files
committed
Merge pull request #495 from jrperritt/optimize-object-upload
[rfr] don't copy file contents for etag
2 parents 4ad4160 + 4fcd3b7 commit d86f958

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

openstack/objectstorage/v1/objects/requests.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package objects
22

33
import (
4-
"bytes"
4+
"bufio"
55
"crypto/hmac"
66
"crypto/md5"
77
"crypto/sha1"
88
"fmt"
99
"io"
10+
"io/ioutil"
1011
"strings"
1112
"time"
1213

@@ -167,7 +168,7 @@ type CreateOpts struct {
167168
ObjectManifest string `h:"X-Object-Manifest"`
168169
TransferEncoding string `h:"Transfer-Encoding"`
169170
Expires string `q:"expires"`
170-
MultipartManifest string `q:"multiple-manifest"`
171+
MultipartManifest string `q:"multipart-manifest"`
171172
Signature string `q:"signature"`
172173
}
173174

@@ -213,19 +214,20 @@ func Create(c *gophercloud.ServiceClient, containerName, objectName string, cont
213214
}
214215

215216
hash := md5.New()
217+
bufioReader := bufio.NewReader(io.TeeReader(content, hash))
218+
io.Copy(ioutil.Discard, bufioReader)
219+
localChecksum := hash.Sum(nil)
220+
221+
h["ETag"] = fmt.Sprintf("%x", localChecksum)
216222

217-
contentBuffer := bytes.NewBuffer([]byte{})
218-
_, err := io.Copy(contentBuffer, io.TeeReader(content, hash))
223+
_, err := content.Seek(0, 0)
219224
if err != nil {
220225
res.Err = err
221226
return res
222227
}
223228

224-
localChecksum := hash.Sum(nil)
225-
h["ETag"] = fmt.Sprintf("%x", localChecksum)
226-
227229
ropts := gophercloud.RequestOpts{
228-
RawBody: strings.NewReader(contentBuffer.String()),
230+
RawBody: content,
229231
MoreHeaders: h,
230232
}
231233

0 commit comments

Comments
 (0)