don't copy file contents for etag
diff --git a/openstack/objectstorage/v1/objects/requests.go b/openstack/objectstorage/v1/objects/requests.go
index c2fbaae..89e7b49 100644
--- a/openstack/objectstorage/v1/objects/requests.go
+++ b/openstack/objectstorage/v1/objects/requests.go
@@ -1,12 +1,13 @@
package objects
import (
- "bytes"
+ "bufio"
"crypto/hmac"
"crypto/md5"
"crypto/sha1"
"fmt"
"io"
+ "io/ioutil"
"strings"
"time"
@@ -213,19 +214,20 @@
}
hash := md5.New()
+ bufioReader := bufio.NewReader(io.TeeReader(content, hash))
+ io.Copy(ioutil.Discard, bufioReader)
+ localChecksum := hash.Sum(nil)
- contentBuffer := bytes.NewBuffer([]byte{})
- _, err := io.Copy(contentBuffer, io.TeeReader(content, hash))
+ h["ETag"] = fmt.Sprintf("%x", localChecksum)
+
+ _, err := content.Seek(0, 0)
if err != nil {
res.Err = err
return res
}
- localChecksum := hash.Sum(nil)
- h["ETag"] = fmt.Sprintf("%x", localChecksum)
-
ropts := gophercloud.RequestOpts{
- RawBody: strings.NewReader(contentBuffer.String()),
+ RawBody: content,
MoreHeaders: h,
}