Skip to content

Commit fad9733

Browse files
committed
[修复阿里云OSS图片上传路径不一致错误]
1 parent 5ed1292 commit fad9733

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

server/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ aliyun-oss:
104104
access-key-secret: 'yourAccessKeySecret'
105105
bucket-name: 'yourBucketName'
106106
bucket-url: 'yourBucketUrl'
107+
base-path: 'yourBasePath'
107108

108109
# tencent cos configuration
109110
tencent-cos:

server/config/oss.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type AliyunOSS struct {
2020
AccessKeySecret string `mapstructure:"access-key-secret" json:"accessKeySecret" yaml:"access-key-secret"`
2121
BucketName string `mapstructure:"bucket-name" json:"bucketName" yaml:"bucket-name"`
2222
BucketUrl string `mapstructure:"bucket-url" json:"bucketUrl" yaml:"bucket-url"`
23+
BasePath string `mapstructure:"base-path" json:"basePath" yaml:"base-path"`
2324
}
2425
type TencentCOS struct {
2526
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`

server/utils/upload/aliyun_oss.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/aliyun/aliyun-oss-go-sdk/oss"
77
"go.uber.org/zap"
88
"mime/multipart"
9-
"path/filepath"
109
"time"
1110
)
1211

@@ -27,7 +26,8 @@ func (*AliyunOSS) UploadFile(file *multipart.FileHeader) (string, string, error)
2726
}
2827
defer f.Close() // 创建文件 defer 关闭
2928
// 上传阿里云路径 文件名格式 自己可以改 建议保证唯一性
30-
yunFileTmpPath := filepath.Join("uploads", time.Now().Format("2006-01-02")) + "/" + file.Filename
29+
//yunFileTmpPath := filepath.Join("uploads", time.Now().Format("2006-01-02")) + "/" + file.Filename
30+
yunFileTmpPath := global.GVA_CONFIG.AliyunOSS.BasePath + "/" + "uploads" + "/" + time.Now().Format("2006-01-02") + "/" + file.Filename
3131

3232
// 上传文件流。
3333
err = bucket.PutObject(yunFileTmpPath, f)

web/src/components/upload/image.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
:before-upload="beforeImageUpload"
1818
:multiple="false"
1919
>
20-
<img v-if="imageUrl" :src="path + imageUrl" class="image">
20+
<img v-if="imageUrl" :src="imageUrl" class="image">
2121
<i v-else class="el-icon-plus image-uploader-icon" />
2222
</el-upload>
2323
</div>

0 commit comments

Comments
 (0)