未验证 提交 63a26dcd 编写于 作者: Sliver_Horn's avatar Sliver_Horn 提交者: GitHub

Merge pull request #1104 from aaronwmy/main

将上传目录访问路径和存储路径分开成两个配置
......@@ -104,7 +104,8 @@ db-list:
# local configuration
local:
path: 'uploads/file'
path: 'uploads/file' # 访问路径
store-path: 'uploads/file' # 存储路径
# autocode configuration
autocode:
......
......@@ -104,7 +104,8 @@ db-list:
# local configuration
local:
path: 'uploads/file'
path: 'uploads/file' # 访问路径
store-path: 'uploads/file' # 存储路径
# autocode configuration
autocode:
......
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"` // 本地文件存储路径
}
......@@ -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.
}
......
......@@ -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())
}
......
......@@ -189,9 +189,12 @@
<el-collapse-item title="oss配置" name="10">
<template v-if="config.system['oss-type'] === 'local'">
<h2>本地文件配置</h2>
<el-form-item label="本地文件路径">
<el-form-item label="本地文件访问路径">
<el-input v-model="config.local.path" />
</el-form-item>
<el-form-item label="本地文件存储路径">
<el-input v-model="config.local['store-path']" />
</el-form-item>
</template>
<template v-if="config.system['oss-type'] === 'qiniu'">
<h2>qiniu上传配置</h2>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册