From 668cad8fe9b8a26273a80584326ca956df5eed0f Mon Sep 17 00:00:00 2001 From: niksis02 Date: Tue, 1 Jul 2025 23:58:00 +0400 Subject: [PATCH] fix: moves the body stream reader to public buckets middleware --- s3api/controllers/base.go | 5 +++-- s3api/middlewares/public-bucket.go | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/s3api/controllers/base.go b/s3api/controllers/base.go index ad31afd4..bf4ff337 100644 --- a/s3api/controllers/base.go +++ b/s3api/controllers/base.go @@ -15,6 +15,7 @@ package controllers import ( + "bytes" "encoding/xml" "errors" "fmt" @@ -2216,7 +2217,7 @@ func (c S3ApiController) PutActions(ctx *fiber.Ctx) error { if bodyi != nil { body = bodyi.(io.Reader) } else { - body = ctx.Request().BodyStream() + body = bytes.NewReader([]byte{}) } res, err := c.be.UploadPart(ctx.Context(), @@ -2702,7 +2703,7 @@ func (c S3ApiController) PutActions(ctx *fiber.Ctx) error { if bodyi != nil { body = bodyi.(io.Reader) } else { - body = ctx.Request().BodyStream() + body = bytes.NewReader([]byte{}) } res, err := c.be.PutObject(ctx.Context(), diff --git a/s3api/middlewares/public-bucket.go b/s3api/middlewares/public-bucket.go index 8d83f89f..10a765e1 100644 --- a/s3api/middlewares/public-bucket.go +++ b/s3api/middlewares/public-bucket.go @@ -218,6 +218,7 @@ func detectS3Action(ctx *fiber.Ctx, isBucketAction bool) (auth.Action, auth.Perm } // UploadPart + utils.ContextKeyBodyReader.Set(ctx, ctx.Request().BodyStream()) return auth.PutObjectAction, auth.PermissionWrite, nil } if ctx.Get("X-Amz-Copy-Source") != "" { @@ -225,6 +226,7 @@ func detectS3Action(ctx *fiber.Ctx, isBucketAction bool) (auth.Action, auth.Perm } // All the other requests are considered as 'PutObject' in the router + utils.ContextKeyBodyReader.Set(ctx, ctx.Request().BodyStream()) return auth.PutObjectAction, auth.PermissionWrite, nil case fiber.MethodPost: if isBucketAction {