diff --git a/api/controller/Editor.go b/api/controller/Editor.go index 31f1ab9..c01308b 100644 --- a/api/controller/Editor.go +++ b/api/controller/Editor.go @@ -80,15 +80,12 @@ func (b *Editor) EditorUpload(c *gin.Context) { return } - fileType := c.PostForm("type") - if fileType == "" { - responses.FailWithMessage("缺少参数", c) - return - } - - fileType = utils.GetExtension(fileType) - if fileType == "" { - fileType = "jpg" + fileType := "jpg" + if file.Filename != "" { + fileType = utils.GetExtension(fileType) + if fileType == "" { + fileType = "jpg" + } } now := time.Now() diff --git a/utils/replace.go b/utils/replace.go index ee4acd3..60c7d98 100644 --- a/utils/replace.go +++ b/utils/replace.go @@ -21,10 +21,10 @@ func AddOssDomain(url string) string { return config.C.Oss.OssCustomDomainName + url } -// GetExtension 解析并返回字符串中 `/` 后面的部分 +// GetExtension 解析并返回字符串中 `.` 后面的部分 func GetExtension(s string) string { // 使用 strings.Split 分割字符串 - parts := strings.Split(s, "/") + parts := strings.Split(s, ".") if len(parts) > 1 { return parts[1] // 返回第二部分 }