From 018999b973711bd6f12ce436eb006c4ac8033a7e Mon Sep 17 00:00:00 2001 From: akira Date: Fri, 12 May 2023 08:00:17 +0000 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87=E6=94=AF?= =?UTF-8?q?=E6=8C=81wbp=E6=A0=BC=E5=BC=8F=EF=BC=8C=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8E=E7=BC=80=E6=96=B9=E5=BC=8F=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: akira --- app/controller/admin/upload.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/app/controller/admin/upload.go b/app/controller/admin/upload.go index 9285495..8799667 100644 --- a/app/controller/admin/upload.go +++ b/app/controller/admin/upload.go @@ -81,8 +81,11 @@ func uploadLocal(c *gin.Context, file *multipart.FileHeader) (string, error) { } func uploadOss(file *multipart.FileHeader) (bool, string) { - fileExt := filepath.Ext(file.Filename) - allowExts := []string{".jpg", ".png", ".gif", ".jpeg"} + fmt.Println(file.Header) + fmt.Println(file.Header.Get("Content-Type")) + var fileExt string + fileExt = strings.Split(file.Header.Get("Content-Type"), "/")[1] + allowExts := []string{"jpg", "png", "gif", "jpeg", "webp"} allowFlag := false for _, ext := range allowExts { if ext == fileExt { @@ -94,16 +97,9 @@ func uploadOss(file *multipart.FileHeader) (bool, string) { return false, "不允许的类型" } - now := time.Now() - // 文件存放路径 - // fileDir := fmt.Sprintf("articles/%s", now.Format("200601")) - // fileDir := fmt.Sprintf("article") - // 文件名称 - timeStamp := now.Unix() - // fileName := fmt.Sprintf("%d%s", timeStamp, fileExt) + timeStamp := time.Now().Unix() // 文件key - // fileKey := filepath.Join(fileDir, fileName) fileKey := fmt.Sprintf("article/%d%s", timeStamp, fileExt) src, err := file.Open() -- Gitee