commit code
This commit is contained in:
@ -34,8 +34,8 @@ func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogi
|
||||
// 上传文件(图片/头像/壁纸等)
|
||||
func (l *UploadLogic) Upload(in *file.UploadRequest) (*file.UploadResponse, error) {
|
||||
bucketName := "default"
|
||||
if in.Folder != "" {
|
||||
bucketName = in.Folder
|
||||
if in.Bucket != "" {
|
||||
bucketName = in.Bucket
|
||||
}
|
||||
|
||||
// 确保 bucket 存在(自动创建)
|
||||
@ -54,6 +54,10 @@ func (l *UploadLogic) Upload(in *file.UploadRequest) (*file.UploadResponse, erro
|
||||
ext := getFileExtension(in.Filename)
|
||||
newFileName := uuid.New().String() + ext
|
||||
|
||||
if in.Folder != "" {
|
||||
newFileName = in.Folder + "/" + newFileName
|
||||
}
|
||||
|
||||
// 上传对象
|
||||
_, err = l.svcCtx.MinioClient.PutObject(l.ctx, bucketName, newFileName,
|
||||
bytes.NewReader(in.Content),
|
||||
|
||||
Reference in New Issue
Block a user