🐛 add dir create

This commit is contained in:
Havoc412 2024-10-20 12:16:35 +08:00
parent 5b7b13f96a
commit 39ad6414b2
2 changed files with 10 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import (
"catface/app/service/upload_file"
"catface/app/utils/response"
"path/filepath"
"strconv"
"github.com/gin-gonic/gin"
)
@ -18,7 +19,7 @@ func (e *Encounters) Create(context *gin.Context) {
// TODO 处理 Photos 文件,然后处理出 Avatar并获取压缩后的 宽高,以及文件的存储路径。
photos := data_transfer.GetStringSlice(context, "photos")
if len(photos) > 0 {
userId := context.GetString(consts.ValidatorPrefix + "user_id")
userId := strconv.Itoa(int(context.GetFloat64(consts.ValidatorPrefix + "user_id")))
avatar := photos[0]
avatarWidth := variable.ConfigYml.GetFloat64("FileUploadSetting.AvatarWidth")

View File

@ -1,6 +1,7 @@
package upload_file
import (
"catface/app/global/variable"
"image"
// "image/jpeg"
"os"
@ -44,6 +45,13 @@ func ResizeImage(srcPath string, dstPath string, targetWidth int) (targetHeight
// draw.CatmullRom.Scale(dstImg, dstImg.Bounds(), srcImg, srcImg.Bounds(), draw.Over, nil)
// Save
// 相关路径不存在,创建目录
if _, err = os.Stat(dstPath); err != nil {
if err = os.MkdirAll(dstPath, os.ModePerm); err != nil {
variable.ZapLog.Error("文件上传创建目录出错" + err.Error())
return
}
}
err = imaging.Save(dstImg, dstPath)
return
}