diff --git a/server/config.yaml b/server/config.yaml index 9d969a7d..716b007f 100644 --- a/server/config.yaml +++ b/server/config.yaml @@ -104,6 +104,7 @@ aliyun-oss: access-key-secret: 'yourAccessKeySecret' bucket-name: 'yourBucketName' bucket-url: 'yourBucketUrl' + base-path: 'yourBasePath' # tencent cos configuration tencent-cos: diff --git a/server/config/oss.go b/server/config/oss.go index a78420af..37957ddf 100644 --- a/server/config/oss.go +++ b/server/config/oss.go @@ -20,6 +20,7 @@ type AliyunOSS struct { AccessKeySecret string `mapstructure:"access-key-secret" json:"accessKeySecret" yaml:"access-key-secret"` BucketName string `mapstructure:"bucket-name" json:"bucketName" yaml:"bucket-name"` BucketUrl string `mapstructure:"bucket-url" json:"bucketUrl" yaml:"bucket-url"` + BasePath string `mapstructure:"base-path" json:"basePath" yaml:"base-path"` } type TencentCOS struct { Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"` diff --git a/server/utils/upload/aliyun_oss.go b/server/utils/upload/aliyun_oss.go index fcba9700..beb7b2bc 100644 --- a/server/utils/upload/aliyun_oss.go +++ b/server/utils/upload/aliyun_oss.go @@ -6,7 +6,6 @@ import ( "github.com/aliyun/aliyun-oss-go-sdk/oss" "go.uber.org/zap" "mime/multipart" - "path/filepath" "time" ) @@ -27,7 +26,8 @@ func (*AliyunOSS) UploadFile(file *multipart.FileHeader) (string, string, error) } defer f.Close() // 创建文件 defer 关闭 // 上传阿里云路径 文件名格式 自己可以改 建议保证唯一性 - yunFileTmpPath := filepath.Join("uploads", time.Now().Format("2006-01-02")) + "/" + file.Filename + //yunFileTmpPath := filepath.Join("uploads", time.Now().Format("2006-01-02")) + "/" + file.Filename + yunFileTmpPath := global.GVA_CONFIG.AliyunOSS.BasePath + "/" + "uploads" + "/" + time.Now().Format("2006-01-02") + "/" + file.Filename // 上传文件流。 err = bucket.PutObject(yunFileTmpPath, f) diff --git a/web/src/components/upload/image.vue b/web/src/components/upload/image.vue index 3db8f8e4..57e7734e 100644 --- a/web/src/components/upload/image.vue +++ b/web/src/components/upload/image.vue @@ -17,7 +17,7 @@ :before-upload="beforeImageUpload" :multiple="false" > - +