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
|
minio: #MinIO 发送图片、视频、文件时需要,请自行申请后替换,必须修改。 客户端初始化InitSDK,中 object_storage参数为minio
|
||||||
bucket: openim
|
bucket: openim
|
||||||
location: us-east-1
|
location: us-east-1
|
||||||
endpoint: http://127.0.0.1:9000
|
` endpoint: http://43.128.5.63:9000
|
||||||
accessKeyID: user12345
|
accessKeyID: user12345
|
||||||
secretAccessKey: key12345
|
secretAccessKey: key12345
|
||||||
|
|
||||||
|
@ -23,9 +23,8 @@ func MinioUploadFile(c *gin.Context) {
|
|||||||
)
|
)
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
log.NewError(req.OperationID, recover())
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), r)
|
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
|
return
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -37,7 +36,11 @@ func MinioUploadFile(c *gin.Context) {
|
|||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
|
||||||
switch req.FileType {
|
switch req.FileType {
|
||||||
case constant.VideoType:
|
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()
|
snapShotFileObj, err := snapShotFile.Open()
|
||||||
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())
|
||||||
@ -45,6 +48,7 @@ func MinioUploadFile(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
snapShotNewName, snapShotNewType := utils.GetNewFileNameAndContentType(snapShotFile.Filename)
|
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})
|
_, 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())
|
||||||
@ -54,7 +58,11 @@ func MinioUploadFile(c *gin.Context) {
|
|||||||
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
|
||||||
}
|
}
|
||||||
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()
|
fileObj, err := file.Open()
|
||||||
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())
|
||||||
@ -62,6 +70,7 @@ func MinioUploadFile(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
newName, newType := utils.GetNewFileNameAndContentType(file.Filename)
|
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})
|
_, err = minioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, newName, fileObj, file.Size, minio.PutObjectOptions{ContentType: newType})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "open file error")
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "open file error")
|
||||||
|
@ -20,6 +20,6 @@ type MinioUploadFileReq struct {
|
|||||||
type MinioUploadFileResp struct {
|
type MinioUploadFileResp struct {
|
||||||
URL string `json:"URL"`
|
URL string `json:"URL"`
|
||||||
NewName string `json:"newName"`
|
NewName string `json:"newName"`
|
||||||
SnapshotURL string `json:"snapshotURL" binding:"omitempty"`
|
SnapshotURL string `json:"snapshotURL,omitempty"`
|
||||||
SnapshotNewName string `json:"snapshotName" binding:"omitempty"`
|
SnapshotNewName string `json:"snapshotName,omitempty"`
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user