diff --git a/server/config.docker.yaml b/server/config.docker.yaml index f6b9529481c03a3db05a1e98ffb120210fae0204..934b7de065b7f576d653fda66dab18954554eb94 100644 --- a/server/config.docker.yaml +++ b/server/config.docker.yaml @@ -104,7 +104,8 @@ db-list: # local configuration local: - path: 'uploads/file' + path: 'uploads/file' # 访问路径 + store-path: 'uploads/file' # 存储路径 # autocode configuration autocode: diff --git a/server/config.yaml b/server/config.yaml index ff41a49d26e85cf8a0c9206bc54e42d852386f96..86b0120115b38561e62e6cd64955a0e48224e1dc 100644 --- a/server/config.yaml +++ b/server/config.yaml @@ -104,7 +104,8 @@ db-list: # local configuration local: - path: 'uploads/file' + path: 'uploads/file' # 访问路径 + store-path: 'uploads/file' # 存储路径 # autocode configuration autocode: diff --git a/server/config/oss_local.go b/server/config/oss_local.go index 5ff1f32414d824da87c5ab828f0360e7d6dfa384..7038d4ad9630cc6b6eec4fb7d0d4a9961e00735e 100644 --- a/server/config/oss_local.go +++ b/server/config/oss_local.go @@ -1,5 +1,6 @@ package config type Local struct { - Path string `mapstructure:"path" json:"path" yaml:"path"` // 本地文件路径 + Path string `mapstructure:"path" json:"path" yaml:"path"` // 本地文件访问路径 + StorePath string `mapstructure:"store-path" json:"store-path" yaml:"store-path"` // 本地文件存储路径 } diff --git a/server/initialize/router.go b/server/initialize/router.go index 9de6121b1f4fbd425b72e4aeaf5e6238ff29a3b1..be8b5b67c8966c95b82bb6546001be3cba0ba08b 100644 --- a/server/initialize/router.go +++ b/server/initialize/router.go @@ -27,7 +27,7 @@ func Routers() *gin.Engine { // Router.Static("/static", "./dist/assets") // dist里面的静态资源 // Router.StaticFile("/", "./dist/index.html") // 前端网页入口页面 - Router.StaticFS(global.GVA_CONFIG.Local.Path, http.Dir(global.GVA_CONFIG.Local.Path)) // 为用户头像和文件提供静态地址 + Router.StaticFS(global.GVA_CONFIG.Local.Path, http.Dir(global.GVA_CONFIG.Local.StorePath)) // 为用户头像和文件提供静态地址 // Router.Use(middleware.LoadTls()) // 如果需要使用https 请打开此中间件 然后前往 core/server.go 将启动模式 更变为 Router.RunTLS("端口","你的cre/pem文件","你的key文件") global.GVA_LOG.Info("use middleware logger") // 跨域,如需跨域可以打开下面的注释 @@ -71,7 +71,7 @@ func Routers() *gin.Engine { exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由 // Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT. - + // Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT. } diff --git a/server/utils/upload/local.go b/server/utils/upload/local.go index aa4dfe77a28a6532ea7ac85df6b801d630de6c72..31aa6e37fd8c455f97602807b5c1752b30b60a32 100644 --- a/server/utils/upload/local.go +++ b/server/utils/upload/local.go @@ -34,13 +34,14 @@ func (*Local) UploadFile(file *multipart.FileHeader) (string, string, error) { // 拼接新文件名 filename := name + "_" + time.Now().Format("20060102150405") + ext // 尝试创建此路径 - mkdirErr := os.MkdirAll(global.GVA_CONFIG.Local.Path, os.ModePerm) + mkdirErr := os.MkdirAll(global.GVA_CONFIG.Local.StorePath, os.ModePerm) if mkdirErr != nil { global.GVA_LOG.Error("function os.MkdirAll() Filed", zap.Any("err", mkdirErr.Error())) return "", "", errors.New("function os.MkdirAll() Filed, err:" + mkdirErr.Error()) } // 拼接路径和文件名 - p := global.GVA_CONFIG.Local.Path + "/" + filename + p := global.GVA_CONFIG.Local.StorePath + "/" + filename + filepath := global.GVA_CONFIG.Local.Path + "/" + filename f, openError := file.Open() // 读取文件 if openError != nil { @@ -62,7 +63,7 @@ func (*Local) UploadFile(file *multipart.FileHeader) (string, string, error) { global.GVA_LOG.Error("function io.Copy() Filed", zap.Any("err", copyErr.Error())) return "", "", errors.New("function io.Copy() Filed, err:" + copyErr.Error()) } - return p, filename, nil + return filepath, filename, nil } //@author: [piexlmax](https://github.com/piexlmax) @@ -75,8 +76,8 @@ func (*Local) UploadFile(file *multipart.FileHeader) (string, string, error) { //@return: error func (*Local) DeleteFile(key string) error { - p := global.GVA_CONFIG.Local.Path + "/" + key - if strings.Contains(p, global.GVA_CONFIG.Local.Path) { + p := global.GVA_CONFIG.Local.StorePath + "/" + key + if strings.Contains(p, global.GVA_CONFIG.Local.StorePath) { if err := os.Remove(p); err != nil { return errors.New("本地文件删除失败, err:" + err.Error()) } diff --git a/web/src/view/systemTools/system/system.vue b/web/src/view/systemTools/system/system.vue index b66cdac987c882f23ab734b35995669949aabcb9..4b27c4368d5378a7e4015fcf79f9fabcd79c13a4 100644 --- a/web/src/view/systemTools/system/system.vue +++ b/web/src/view/systemTools/system/system.vue @@ -189,9 +189,12 @@