diff --git a/internal/api/third/minio_storage_credential.go b/internal/api/third/minio_storage_credential.go index 65758c3fb..22bf6f6da 100644 --- a/internal/api/third/minio_storage_credential.go +++ b/internal/api/third/minio_storage_credential.go @@ -21,7 +21,15 @@ func MinioUploadFile(c *gin.Context) { req apiStruct.MinioUploadFileReq resp apiStruct.MinioUploadFileResp ) - if err := c.BindJSON(&req); err != nil { + 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}) + return + } + }() + if err := c.Bind(&req); err != nil { log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error()) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) return @@ -34,12 +42,14 @@ func MinioUploadFile(c *gin.Context) { if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error()) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) + return } snapShotNewName, snapShotNewType := utils.GetNewFileNameAndContentType(snapShotFile.Filename) _, 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()) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) + return } resp.SnapshotURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.Bucket + "/" + snapShotNewName resp.SnapshotNewName = snapShotNewName diff --git a/pkg/base_info/minio_api_struct.go b/pkg/base_info/minio_api_struct.go index d031244ed..e7bb902cc 100644 --- a/pkg/base_info/minio_api_struct.go +++ b/pkg/base_info/minio_api_struct.go @@ -13,8 +13,8 @@ type MiniostorageCredentialResp struct { } type MinioUploadFileReq struct { - OperationID string `json:"operationID"` - FileType int `json:"fileType"` + OperationID string `form:"operationID"` + FileType int `form:"fileType"` } type MinioUploadFileResp struct {