Skip to content

Commit 61cd015

Browse files
committed
fix: potential error when using minio as s3 backend
1 parent 2bc1c94 commit 61cd015

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

hupload/handlers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"path"
1313
"strconv"
1414

15+
"github.com/aws/smithy-go"
1516
"github.com/ybizeul/apiws/auth"
1617
"github.com/ybizeul/hupload/internal/storage"
1718
)
@@ -156,6 +157,7 @@ func (h *Hupload) postItem(w http.ResponseWriter, r *http.Request) {
156157

157158
b := bufio.NewReader(np)
158159
item, err := h.Config.Storage.CreateItem(r.Context(), r.PathValue("share"), r.PathValue("item"), int64(cl), b)
160+
var apiErr smithy.APIError
159161
if err != nil {
160162
switch {
161163
case errors.Is(err, storage.ErrMaxShareSizeReached):
@@ -165,6 +167,10 @@ func (h *Hupload) postItem(w http.ResponseWriter, r *http.Request) {
165167
writeError(w, http.StatusInsufficientStorage, "max item size reached")
166168
return
167169
}
170+
if errors.As(err, &apiErr) {
171+
writeError(w, http.StatusBadRequest, apiErr.ErrorMessage())
172+
return
173+
}
168174
writeError(w, http.StatusInternalServerError, err.Error())
169175
return
170176
}

hupload/internal/storage/s3.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sort"
1212
"time"
1313

14+
"github.com/aws/aws-sdk-go-v2/aws"
1415
"github.com/aws/aws-sdk-go-v2/config"
1516
"github.com/aws/aws-sdk-go-v2/credentials"
1617
"github.com/aws/aws-sdk-go-v2/service/s3"
@@ -67,6 +68,7 @@ func (b *S3Backend) initialize() error {
6768
config.WithHTTPClient(&http.Client{
6869
Timeout: 0,
6970
}),
71+
config.WithRequestChecksumCalculation(aws.RequestChecksumCalculationWhenRequired),
7072
)
7173
if err != nil {
7274
return err

0 commit comments

Comments
 (0)