Skip to content

Commit 6dd97af

Browse files
authored
Merge pull request #110 from tombuildsstuff/bugfix/encoding-storage-blob-from-content
bugfix: don't use req.Marshal to encode a binary payload…
2 parents 8efc5bb + 8d8b3c5 commit 6dd97af

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

storage/2023-11-03/blob/blobs/get.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package blobs
33
import (
44
"context"
55
"fmt"
6+
"io"
67
"net/http"
78
"strings"
89

@@ -65,13 +66,16 @@ func (c Client) Get(ctx context.Context, containerName, blobName string, input G
6566
var resp *client.Response
6667
resp, err = req.Execute(ctx)
6768
if resp != nil {
68-
result.Contents = &[]byte{}
6969
result.HttpResponse = resp.Response
7070

71-
err = resp.Unmarshal(result.Contents)
72-
if err != nil {
73-
err = fmt.Errorf("unmarshalling response: %+v", err)
74-
return
71+
if resp.Body != nil {
72+
defer resp.Body.Close()
73+
respBody, err := io.ReadAll(resp.Body)
74+
if err != nil {
75+
return result, fmt.Errorf("could not parse response body")
76+
}
77+
78+
result.Contents = &respBody
7579
}
7680
}
7781
if err != nil {

storage/2023-11-03/blob/blobs/put_block_blob.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package blobs
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
7+
"io"
68
"net/http"
79
"strconv"
810
"strings"
@@ -78,10 +80,9 @@ func (c Client) PutBlockBlob(ctx context.Context, containerName, blobName string
7880
return
7981
}
8082

81-
err = req.Marshal(input.Content)
82-
if err != nil {
83-
err = fmt.Errorf("marshalling request: %+v", err)
84-
return
83+
if input.Content != nil {
84+
req.ContentLength = int64(len(*input.Content))
85+
req.Body = io.NopCloser(bytes.NewReader(*input.Content))
8586
}
8687

8788
var resp *client.Response

0 commit comments

Comments
 (0)