|
@@ -5,11 +5,9 @@ import (
|
|
|
"errors"
|
|
|
"eta/eta_mini_crm_ht/utils"
|
|
|
"fmt"
|
|
|
- "log"
|
|
|
- "time"
|
|
|
-
|
|
|
"github.com/minio/minio-go/v7"
|
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
type MinioOss struct{}
|
|
@@ -37,7 +35,7 @@ func (m *MinioOss) UploadFile(fileName, filePath, savePath string) (string, erro
|
|
|
Secure: useSSL,
|
|
|
})
|
|
|
if err != nil {
|
|
|
- log.Fatalln(err)
|
|
|
+ utils.FileLog.Error(err.Error())
|
|
|
return "1", err
|
|
|
}
|
|
|
bucketName := utils.MinIoBucketname
|
|
@@ -53,7 +51,7 @@ func (m *MinioOss) UploadFile(fileName, filePath, savePath string) (string, erro
|
|
|
}
|
|
|
_, err = minioClient.FPutObject(ctx, bucketName, path, filePath, minio.PutObjectOptions{})
|
|
|
if err != nil {
|
|
|
- log.Fatalln(err)
|
|
|
+ utils.FileLog.Error(err.Error())
|
|
|
return "3", err
|
|
|
}
|
|
|
resourceUrl := utils.MinIoPdfhost + path
|
|
@@ -71,3 +69,76 @@ func (m *MinioOss) GetUploadToken() (token OssToken, err error) {
|
|
|
token.Port = utils.MinIoPort
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+func (m *MinioOss) GetFile(filePath, savePath string) (err error) {
|
|
|
+ if utils.MinIoAccessKeyId == `` || utils.MinIoAccessKeySecret == `` {
|
|
|
+ err = errors.New("MinIo信息未配置")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ctx := context.Background()
|
|
|
+ // 此处兼容一下前后端endpoint不一致的情况, 前端用minio_endpoint后端用minio_back_endpoint, minio_back_endpoint为空则都取前者
|
|
|
+ endpoint := utils.MinIoEndpoint
|
|
|
+ if utils.MinIoBackEndpoint != "" {
|
|
|
+ endpoint = utils.MinIoBackEndpoint
|
|
|
+ }
|
|
|
+ accessKeyID := utils.MinIoAccessKeyId
|
|
|
+ secretAccessKey := utils.MinIoAccessKeySecret
|
|
|
+ useSSL := false
|
|
|
+ if utils.MinIoUseSSL == "true" {
|
|
|
+ useSSL = true
|
|
|
+ }
|
|
|
+ minioClient, err := minio.New(endpoint, &minio.Options{
|
|
|
+ Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
|
|
|
+ Secure: useSSL,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Error(err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ bucketName := utils.MinIoBucketname
|
|
|
+ exists, errBucketExists := minioClient.BucketExists(ctx, bucketName)
|
|
|
+ if errBucketExists != nil || !exists {
|
|
|
+ err = fmt.Errorf("BucketExists: %v; err: %v", exists, errBucketExists)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = minioClient.FGetObject(ctx, bucketName, filePath, savePath, minio.GetObjectOptions{})
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Error(err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+func (m *MinioOss) MultiUploadFile() (err error) {
|
|
|
+ if utils.MinIoAccessKeyId == `` || utils.MinIoAccessKeySecret == `` {
|
|
|
+ err = errors.New("MinIo信息未配置")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ctx := context.Background()
|
|
|
+ // 此处兼容一下前后端endpoint不一致的情况, 前端用minio_endpoint后端用minio_back_endpoint, minio_back_endpoint为空则都取前者
|
|
|
+ endpoint := utils.MinIoEndpoint
|
|
|
+ if utils.MinIoBackEndpoint != "" {
|
|
|
+ endpoint = utils.MinIoBackEndpoint
|
|
|
+ }
|
|
|
+ accessKeyID := utils.MinIoAccessKeyId
|
|
|
+ secretAccessKey := utils.MinIoAccessKeySecret
|
|
|
+ useSSL := false
|
|
|
+ if utils.MinIoUseSSL == "true" {
|
|
|
+ useSSL = true
|
|
|
+ }
|
|
|
+ minioClient, err := minio.New(endpoint, &minio.Options{
|
|
|
+ Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
|
|
|
+ Secure: useSSL,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Error(err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ bucketName := utils.MinIoBucketname
|
|
|
+ exists, errBucketExists := minioClient.BucketExists(ctx, bucketName)
|
|
|
+ if errBucketExists != nil || !exists {
|
|
|
+ err = fmt.Errorf("BucketExists: %v; err: %v", exists, errBucketExists)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|