From ef5362e1c4f050dc9f68e3832a3ab40192109580 Mon Sep 17 00:00:00 2001 From: jjxu <428192774@qq.com> Date: Tue, 17 Jun 2025 10:51:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=90=8E=E6=96=87=E4=BB=B6url=E6=97=A0=E6=B3=95=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=B8=AD=E9=97=B4=E4=BB=B6=E6=89=93=E5=8D=B0=E4=BA=8C=E8=BF=9B?= =?UTF-8?q?=E5=88=B6=E6=96=87=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/middleware/logging.go | 10 ++++++---- pkg/service/upload/upload.go | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/middleware/logging.go b/pkg/middleware/logging.go index f58b6db..48f286a 100644 --- a/pkg/middleware/logging.go +++ b/pkg/middleware/logging.go @@ -24,11 +24,13 @@ func NewLogger() gin.HandlerFunc { latencyTime := endTime.Sub(startTime) // 请求方式 path := c.Request.URL.Path query := c.Request.URL.RawQuery - data, _ := ioutil.ReadAll(c.Request.Body) - log.Printf("[%s] %s %d %s %s %s %s %s %s", path, c.Request.Method, c.Writer.Status(), query, - string(data), c.ClientIP(), c.Request.UserAgent(), c.Errors.ByType(gin.ErrorTypePrivate).String(), latencyTime.String()) + if _, err := c.FormFile("file"); err != nil { + data, _ := ioutil.ReadAll(c.Request.Body) + log.Printf("[%s] %s %d %s %s %s %s %s %s", path, c.Request.Method, c.Writer.Status(), query, + string(data), c.ClientIP(), c.Request.UserAgent(), c.Errors.ByType(gin.ErrorTypePrivate).String(), latencyTime.String()) - c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(data)) + c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(data)) + } c.Next() } } diff --git a/pkg/service/upload/upload.go b/pkg/service/upload/upload.go index c2305bd..54282fc 100644 --- a/pkg/service/upload/upload.go +++ b/pkg/service/upload/upload.go @@ -337,7 +337,8 @@ func UploadWithBuffer(fileBuffer *bytes.Buffer, cloudStoreSubPath string) (url s return } cloudStoreSubPath = getEnvDir(cloudStoreSubPath) - url, err = Client.PutObjectFromBytes(config.ConfigData.Oss.BucketName, cloudStoreSubPath, fileBuffer.Bytes()) + _, err = Client.PutObjectFromBytes(config.ConfigData.Oss.BucketName, cloudStoreSubPath, fileBuffer.Bytes()) + url = config.ConfigData.Oss.CdnHost + "/" + cloudStoreSubPath return } func getEnvDir(cloudStoreSubPath string) (ep string) {