mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-04 17:15:58 +08:00
minio upload api
This commit is contained in:
+7
-4
@@ -1,9 +1,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -26,11 +28,12 @@ func MkDir(path string) error {
|
||||
return os.MkdirAll(path, os.ModePerm)
|
||||
}
|
||||
|
||||
func GetNewFileNameAndContentType(fileType string) (string, string) {
|
||||
newName := fmt.Sprintf("%d-%d%s", time.Now().UnixNano(), rand.Int(), fileType)
|
||||
func GetNewFileNameAndContentType(fileName string, fileType int) (string, string) {
|
||||
suffix := path.Ext(fileName)
|
||||
newName := fmt.Sprintf("%d-%d%s", time.Now().UnixNano(), rand.Int(), fileName)
|
||||
contentType := ""
|
||||
if fileType == "img" {
|
||||
contentType = "image/" + fileType[1:]
|
||||
if fileType == constant.ImageType {
|
||||
contentType = "image/" + suffix[1:]
|
||||
}
|
||||
return newName, contentType
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user