diff --git a/api/handler/multipart_upload.go b/api/handler/multipart_upload.go index 1795c29..17c592d 100644 --- a/api/handler/multipart_upload.go +++ b/api/handler/multipart_upload.go @@ -205,10 +205,7 @@ func (h *handler) UploadPartHandler(w http.ResponseWriter, r *http.Request) { return } - var size uint64 - if r.ContentLength > 0 { - size = uint64(r.ContentLength) - } + size := h.getPutPayloadSize(r) p := &layer.UploadPartParams{ Info: &layer.UploadInfoParams{ diff --git a/api/handler/put.go b/api/handler/put.go index e740cbb..59c1499 100644 --- a/api/handler/put.go +++ b/api/handler/put.go @@ -242,10 +242,7 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) { metadata[api.ContentEncoding] = encodings } - var size uint64 - if r.ContentLength > 0 { - size = uint64(r.ContentLength) - } + size := h.getPutPayloadSize(r) params := &layer.PutObjectParams{ BktInfo: bktInfo, diff --git a/api/handler/util.go b/api/handler/util.go index dde5274..3665488 100644 --- a/api/handler/util.go +++ b/api/handler/util.go @@ -106,6 +106,23 @@ func (h *handler) getBucketAndCheckOwner(r *http.Request, bucket string, header return bktInfo, checkOwner(bktInfo, expected) } +func (h *handler) getPutPayloadSize(r *http.Request) uint64 { + decodeContentSize := r.Header.Get(api.AmzDecodedContentLength) + decodedSize, err := strconv.Atoi(decodeContentSize) + if err != nil { + decodedSize = 0 + } + + var size uint64 + if decodedSize > 0 { + size = uint64(decodedSize) + } else if r.ContentLength > 0 { + size = uint64(r.ContentLength) + } + + return size +} + func parseRange(s string) (*layer.RangeParams, error) { if s == "" { return nil, nil