fit Images Save with root Path

This commit is contained in:
Havoc412 2024-11-12 11:31:40 +08:00
parent 6b8fabb8d8
commit b7c7bf92d6
4 changed files with 11 additions and 8 deletions

View File

@ -19,7 +19,7 @@ type Upload struct {
func (u *Upload) StartUpload(context *gin.Context) {
// TODO 如果之后要存储到 Linux 服务器上特殊路径下,就需要修改这里。
dir_name := context.GetString(consts.ValidatorPrefix + "dir_name")
savePath := filepath.Join(variable.BasePath, variable.ConfigYml.GetString("FileUploadSetting.UploadFileSavePath"), dir_name)
savePath := filepath.Join(variable.ConfigYml.GetString("FileUploadSetting.UploadFileSavePath"), dir_name)
if r, finnalSavePath := upload_file.Upload(context, savePath); r == true {
response.Success(context, consts.CurdStatusOkMsg, finnalSavePath)

View File

@ -19,6 +19,7 @@ type Create struct {
AnimalsId []int `form:"animals_id" json:"animals_id" binding:"required"`
Title string `form:"title" json:"title" binding:"required"`
Content string `form:"content" json:"content"`
Level int `form:"level" json:"level"`
// Avatar string `form:"avatar" json:"avatar"`
Photos []string `form:"photos" json:"photos"` // INFO 如果 Photo 为空,那就选取 Animals 的 Avatar

View File

@ -44,8 +44,9 @@ func Upload(context *gin.Context, savePath string) (r bool, finnalSavePath inter
}
// 文件上传可以设置按照 xxx年-xx月 格式存储
// INFO 但这个 returnPath 我还基本没有用到。
func generateYearMonthPath(savePathPre string) (string, string) {
returnPath := variable.BasePath + variable.ConfigYml.GetString("FileUploadSetting.UploadFileReturnPath")
returnPath := variable.BasePath + variable.ConfigYml.GetString("FileUploadSetting.UploadFileReturnPath") // UPDATE 因为没用到,所以就先不调整了。
curYearMonth := time.Now().In(time.Local).Format("2006_01")
newSavePathPre := filepath.Join(savePathPre, curYearMonth)
newReturnPathPre := filepath.Join(returnPath, curYearMonth)

View File

@ -35,7 +35,7 @@ Redis:
Logs:
GinLogName: "/store/logs/gin.log" #设置 gin 框架的接口访问日志
GoSkeletonLogName: "/store/logs/skeleton.log" #设置GoSkeleton项目骨架运行时日志文件名注意该名称不要与上一条重复 ,避免和 gin 框架的日志掺杂一起,造成混乱。
GoSkeletonLogName: "/store/logs/skeleton.log" #设置GoSkeleton项目骨架运行时日志文件名注意该名称不要与上一条重复 ,避免和 gin 框架的日志掺杂一起,造成混乱。
TextFormat: "json" #记录日志的格式参数选项console、json console 表示一般的文本格式
TimePrecision: "millisecond" #记录日志时相关的时间精度该参数选项second 、 millisecond 分别表示 秒 和 毫秒 ,默认为毫秒级别
MaxSize: 10 #每个日志的最大尺寸(以MB为单位 超过该值,系统将会自动进行切割
@ -56,11 +56,12 @@ SnowFlake:
SnowFlakeMachineId: 2 #如果本项目同时部署在多台机器并且需要同时使用该算法请为每一台机器设置不同的ID区间范围: [0,1023]
FileUploadSetting:
Size: 32 #设置上传文件的最大值单位M注意 如果go前置nginx服务器nginx 默认限制文件上传大小为 50 M ,用户上传文件限制还需要继续修改 nginx 配置
UploadFileField: "file" #post上传文件时表单的键名
UploadFileSavePath: "/public/nginx/" #上传文件保存在路径, 该路径与 BasePath 进行拼接使用
UploadFileReturnPath: "" # 文件上后返回的路径由于程序会自动创建软连接自动将资源定位到实际路径所有资源的访问入口建议都从public开始
AllowMimeType: #允许的文件mime类型列表
Size: 32 # 设置上传文件的最大值单位M注意 如果go前置nginx服务器nginx 默认限制文件上传大小为 50 M ,用户上传文件限制还需要继续修改 nginx 配置
UploadFileField: "file" # post上传文件时表单的键名
# TODO 为了方便后续兼容服务器上的 Nginx直接采取绝对路径
UploadFileSavePath: "D:/.File Data/GoProject/catface_back/public/nginx" # 上传文件保存在路径, 该路径与 BasePath 进行拼接使用
UploadFileReturnPath: "" # 文件上后返回的路径由于程序会自动创建软连接自动将资源定位到实际路径所有资源的访问入口建议都从public开始
AllowMimeType: #允许的文件mime类型列表
- "image/jpeg" #jpg、jpeg图片格式
- "image/png" #png图片格式
# - "image/x-icon" #ico图片