Skip to content

Commit

Permalink
Merge pull request #110 from tombuildsstuff/bugfix/encoding-storage-b…
Browse files Browse the repository at this point in the history
…lob-from-content

bugfix: don't use req.Marshal to encode a binary payload…
  • Loading branch information
manicminer authored Mar 22, 2024
2 parents 8efc5bb + 8d8b3c5 commit 6dd97af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
14 changes: 9 additions & 5 deletions storage/2023-11-03/blob/blobs/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package blobs
import (
"context"
"fmt"
"io"
"net/http"
"strings"

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

err = resp.Unmarshal(result.Contents)
if err != nil {
err = fmt.Errorf("unmarshalling response: %+v", err)
return
if resp.Body != nil {
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return result, fmt.Errorf("could not parse response body")
}

result.Contents = &respBody
}
}
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions storage/2023-11-03/blob/blobs/put_block_blob.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package blobs

import (
"bytes"
"context"
"fmt"
"io"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -78,10 +80,9 @@ func (c Client) PutBlockBlob(ctx context.Context, containerName, blobName string
return
}

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

var resp *client.Response
Expand Down

0 comments on commit 6dd97af

Please sign in to comment.