This commit is contained in:
wangchuxiao 2022-03-23 16:13:18 +08:00
parent 4cdcdee8e4
commit 4bdb4cbbb5
2 changed files with 13 additions and 3 deletions

View File

@ -21,7 +21,15 @@ func MinioUploadFile(c *gin.Context) {
req apiStruct.MinioUploadFileReq req apiStruct.MinioUploadFileReq
resp apiStruct.MinioUploadFileResp 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()) log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return return
@ -34,12 +42,14 @@ func MinioUploadFile(c *gin.Context) {
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
} }
snapShotNewName, snapShotNewType := utils.GetNewFileNameAndContentType(snapShotFile.Filename) snapShotNewName, snapShotNewType := utils.GetNewFileNameAndContentType(snapShotFile.Filename)
_, err = minioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, snapShotNewName, snapShotFileObj, snapShotFile.Size, minio.PutObjectOptions{ContentType: snapShotNewType}) _, err = minioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, snapShotNewName, snapShotFileObj, snapShotFile.Size, minio.PutObjectOptions{ContentType: snapShotNewType})
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "PutObject snapShotFile error", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "PutObject snapShotFile error", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": 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.SnapshotURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.Bucket + "/" + snapShotNewName
resp.SnapshotNewName = snapShotNewName resp.SnapshotNewName = snapShotNewName

View File

@ -13,8 +13,8 @@ type MiniostorageCredentialResp struct {
} }
type MinioUploadFileReq struct { type MinioUploadFileReq struct {
OperationID string `json:"operationID"` OperationID string `form:"operationID"`
FileType int `json:"fileType"` FileType int `form:"fileType"`
} }
type MinioUploadFileResp struct { type MinioUploadFileResp struct {