From ddf9a4fbfa27c22fd7b68faabf412da8ee2f1e0b Mon Sep 17 00:00:00 2001 From: alimy Date: Sun, 5 Jun 2022 20:21:41 +0800 Subject: [PATCH] fixed issues #58 that upload attachment failure --- internal/routers/api/attachment.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/internal/routers/api/attachment.go b/internal/routers/api/attachment.go index 37cdcec6..16203525 100644 --- a/internal/routers/api/attachment.go +++ b/internal/routers/api/attachment.go @@ -93,14 +93,6 @@ func UploadAttachment(c *gin.Context) { return } - fileReader, err := fileHeader.Open() - if err != nil { - global.Logger.Errorf("Attachment file read err: %v", err) - response.ToErrorResponse(errcode.FileUploadFailed) - return - } - defer fileReader.Close() - // 生成随机路径 randomPath := uuid.Must(uuid.NewV4()).String() ossSavePath := uploadType + "/" + GeneratePath(randomPath[:8]) + "/" + randomPath[9:] + fileExt @@ -112,14 +104,14 @@ func UploadAttachment(c *gin.Context) { return } - bucket, err := client.Bucket("paopao-assets") + bucket, err := client.Bucket(global.AliossSetting.AliossBucket) if err != nil { global.Logger.Errorf("client.Bucket err: %v", err) response.ToErrorResponse(errcode.FileUploadFailed) return } - err = bucket.PutObject(ossSavePath, fileReader) + err = bucket.PutObject(ossSavePath, file) if err != nil { global.Logger.Errorf("bucket.PutObject err: %v", err) response.ToErrorResponse(errcode.FileUploadFailed)