Browse Source
Merge pull request #528 from hxcode/develop
aliyun_oss,qiniu,tencent_cos: fix file open close
main
奇淼(piexlmax
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
3 additions and
1 deletions
-
server/utils/upload/aliyun_oss.go
-
server/utils/upload/qiniu.go
-
server/utils/upload/tencent_cos.go
|
@ -25,7 +25,7 @@ func (*AliyunOSS) UploadFile(file *multipart.FileHeader) (string, string, error) |
|
|
global.GVA_LOG.Error("function file.Open() Failed", zap.Any("err", openError.Error())) |
|
|
global.GVA_LOG.Error("function file.Open() Failed", zap.Any("err", openError.Error())) |
|
|
return "", "", errors.New("function file.Open() Failed, err:" + openError.Error()) |
|
|
return "", "", errors.New("function file.Open() Failed, err:" + openError.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 |
|
|
|
|
|
|
|
|
|
@ -38,6 +38,7 @@ func (*Qiniu) UploadFile(file *multipart.FileHeader) (string, string, error) { |
|
|
|
|
|
|
|
|
return "", "", errors.New("function file.Open() Filed, err:" + openError.Error()) |
|
|
return "", "", errors.New("function file.Open() Filed, err:" + openError.Error()) |
|
|
} |
|
|
} |
|
|
|
|
|
defer f.Close() // 创建文件 defer 关闭
|
|
|
fileKey := fmt.Sprintf("%d%s", time.Now().Unix(), file.Filename) // 文件名格式 自己可以改 建议保证唯一性
|
|
|
fileKey := fmt.Sprintf("%d%s", time.Now().Unix(), file.Filename) // 文件名格式 自己可以改 建议保证唯一性
|
|
|
putErr := formUploader.Put(context.Background(), &ret, upToken, fileKey, f, file.Size, &putExtra) |
|
|
putErr := formUploader.Put(context.Background(), &ret, upToken, fileKey, f, file.Size, &putExtra) |
|
|
if putErr != nil { |
|
|
if putErr != nil { |
|
|
|
@ -24,6 +24,7 @@ func (*TencentCOS) UploadFile(file *multipart.FileHeader) (string, string, error |
|
|
global.GVA_LOG.Error("function file.Open() Filed", zap.Any("err", openError.Error())) |
|
|
global.GVA_LOG.Error("function file.Open() Filed", zap.Any("err", openError.Error())) |
|
|
return "", "", errors.New("function file.Open() Filed, err:" + openError.Error()) |
|
|
return "", "", errors.New("function file.Open() Filed, err:" + openError.Error()) |
|
|
} |
|
|
} |
|
|
|
|
|
defer f.Close() // 创建文件 defer 关闭
|
|
|
fileKey := fmt.Sprintf("%d%s", time.Now().Unix(), file.Filename) |
|
|
fileKey := fmt.Sprintf("%d%s", time.Now().Unix(), file.Filename) |
|
|
|
|
|
|
|
|
_, err := client.Object.Put(context.Background(), global.GVA_CONFIG.TencentCOS.PathPrefix+"/"+fileKey, f, nil) |
|
|
_, err := client.Object.Put(context.Background(), global.GVA_CONFIG.TencentCOS.PathPrefix+"/"+fileKey, f, nil) |
|
|