[修复阿里云OSS图片上传路径不一致错误]

This commit is contained in:
csnero
2021-06-26 20:54:12 +08:00
parent 5ed1292503
commit fad9733802
4 changed files with 5 additions and 3 deletions

View File

@@ -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)