mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
mongo
This commit is contained in:
parent
4bdb4cbbb5
commit
df4a75f4b0
@ -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
|
||||
|
||||
|
@ -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")
|
||||
|
@ -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"`
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user