🐛 add dir create
This commit is contained in:
parent
5b7b13f96a
commit
39ad6414b2
@ -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")
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user