fixed issues #58 that upload attachment failure

pull/60/head
alimy 3 years ago
parent 0884072bbc
commit ddf9a4fbfa

@ -93,14 +93,6 @@ func UploadAttachment(c *gin.Context) {
return return
} }
fileReader, err := fileHeader.Open()
if err != nil {
global.Logger.Errorf("Attachment file read err: %v", err)
response.ToErrorResponse(errcode.FileUploadFailed)
return
}
defer fileReader.Close()
// 生成随机路径 // 生成随机路径
randomPath := uuid.Must(uuid.NewV4()).String() randomPath := uuid.Must(uuid.NewV4()).String()
ossSavePath := uploadType + "/" + GeneratePath(randomPath[:8]) + "/" + randomPath[9:] + fileExt ossSavePath := uploadType + "/" + GeneratePath(randomPath[:8]) + "/" + randomPath[9:] + fileExt
@ -112,14 +104,14 @@ func UploadAttachment(c *gin.Context) {
return return
} }
bucket, err := client.Bucket("paopao-assets") bucket, err := client.Bucket(global.AliossSetting.AliossBucket)
if err != nil { if err != nil {
global.Logger.Errorf("client.Bucket err: %v", err) global.Logger.Errorf("client.Bucket err: %v", err)
response.ToErrorResponse(errcode.FileUploadFailed) response.ToErrorResponse(errcode.FileUploadFailed)
return return
} }
err = bucket.PutObject(ossSavePath, fileReader) err = bucket.PutObject(ossSavePath, file)
if err != nil { if err != nil {
global.Logger.Errorf("bucket.PutObject err: %v", err) global.Logger.Errorf("bucket.PutObject err: %v", err)
response.ToErrorResponse(errcode.FileUploadFailed) response.ToErrorResponse(errcode.FileUploadFailed)

Loading…
Cancel
Save