diff --git a/app/controller/admin/upload.go b/app/controller/admin/upload.go index 92854953e7a64f8cae851bb16dba61f24a137643..8799667789a55d8eb5e5986526229c68cc4a6490 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()