diff --git a/config/config.yaml b/config/config.yaml index 21ded2735..a5ca9d155 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -90,7 +90,7 @@ credential: #腾讯cos,发送图片、视频、文件时需要,请自行申 minio: #MinIO 发送图片、视频、文件时需要,请自行申请后替换,必须修改。 客户端初始化InitSDK,中 object_storage参数为minio bucket: openim location: us-east-1 - endpoint: http://127.0.0.1:9000 +` endpoint: http://43.128.5.63:9000 accessKeyID: user12345 secretAccessKey: key12345 diff --git a/internal/api/third/minio_storage_credential.go b/internal/api/third/minio_storage_credential.go index 22bf6f6da..56887107c 100644 --- a/internal/api/third/minio_storage_credential.go +++ b/internal/api/third/minio_storage_credential.go @@ -23,9 +23,8 @@ func MinioUploadFile(c *gin.Context) { ) defer func() { if r := recover(); r != nil { - log.NewError(req.OperationID, recover()) log.NewError(req.OperationID, utils.GetSelfFuncName(), r) - c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": r}) + c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "missing file or snapShot args"}) return } }() @@ -37,7 +36,11 @@ func MinioUploadFile(c *gin.Context) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req) switch req.FileType { case constant.VideoType: - snapShotFile, _ := c.FormFile("snapShot") + snapShotFile, err := c.FormFile("snapShot") + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "missing snapshot arg: " + err.Error()}) + return + } snapShotFileObj, err := snapShotFile.Open() if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error()) @@ -45,6 +48,7 @@ func MinioUploadFile(c *gin.Context) { return } snapShotNewName, snapShotNewType := utils.GetNewFileNameAndContentType(snapShotFile.Filename) + log.Debug(req.OperationID, utils.GetSelfFuncName(), snapShotNewName, snapShotNewType) _, err = minioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, snapShotNewName, snapShotFileObj, snapShotFile.Size, minio.PutObjectOptions{ContentType: snapShotNewType}) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "PutObject snapShotFile error", err.Error()) @@ -54,7 +58,11 @@ func MinioUploadFile(c *gin.Context) { resp.SnapshotURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.Bucket + "/" + snapShotNewName resp.SnapshotNewName = snapShotNewName } - file, _ := c.FormFile("file") + file, err := c.FormFile("file") + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "missing snapshot arg: " + err.Error()}) + return + } fileObj, err := file.Open() if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error()) @@ -62,6 +70,7 @@ func MinioUploadFile(c *gin.Context) { return } newName, newType := utils.GetNewFileNameAndContentType(file.Filename) + log.Debug(req.OperationID, utils.GetSelfFuncName(), newName, newType) _, err = minioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, newName, fileObj, file.Size, minio.PutObjectOptions{ContentType: newType}) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "open file error") diff --git a/pkg/base_info/minio_api_struct.go b/pkg/base_info/minio_api_struct.go index e7bb902cc..51e062c67 100644 --- a/pkg/base_info/minio_api_struct.go +++ b/pkg/base_info/minio_api_struct.go @@ -20,6 +20,6 @@ type MinioUploadFileReq struct { type MinioUploadFileResp struct { URL string `json:"URL"` NewName string `json:"newName"` - SnapshotURL string `json:"snapshotURL" binding:"omitempty"` - SnapshotNewName string `json:"snapshotName" binding:"omitempty"` + SnapshotURL string `json:"snapshotURL,omitempty"` + SnapshotNewName string `json:"snapshotName,omitempty"` }