|
@@ -5,11 +5,9 @@ import (
|
|
"errors"
|
|
"errors"
|
|
"eta/eta_mini_crm_ht/utils"
|
|
"eta/eta_mini_crm_ht/utils"
|
|
"fmt"
|
|
"fmt"
|
|
- "log"
|
|
|
|
- "time"
|
|
|
|
-
|
|
|
|
"github.com/minio/minio-go/v7"
|
|
"github.com/minio/minio-go/v7"
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
|
|
+ "time"
|
|
)
|
|
)
|
|
|
|
|
|
type MinioOss struct{}
|
|
type MinioOss struct{}
|
|
@@ -37,7 +35,7 @@ func (m *MinioOss) UploadFile(fileName, filePath, savePath string) (string, erro
|
|
Secure: useSSL,
|
|
Secure: useSSL,
|
|
})
|
|
})
|
|
if err != nil {
|
|
if err != nil {
|
|
- log.Fatalln(err)
|
|
|
|
|
|
+ utils.FileLog.Error(err.Error())
|
|
return "1", err
|
|
return "1", err
|
|
}
|
|
}
|
|
bucketName := utils.MinIoBucketname
|
|
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{})
|
|
_, err = minioClient.FPutObject(ctx, bucketName, path, filePath, minio.PutObjectOptions{})
|
|
if err != nil {
|
|
if err != nil {
|
|
- log.Fatalln(err)
|
|
|
|
|
|
+ utils.FileLog.Error(err.Error())
|
|
return "3", err
|
|
return "3", err
|
|
}
|
|
}
|
|
resourceUrl := utils.MinIoPdfhost + path
|
|
resourceUrl := utils.MinIoPdfhost + path
|
|
@@ -71,3 +69,76 @@ func (m *MinioOss) GetUploadToken() (token OssToken, err error) {
|
|
token.Port = utils.MinIoPort
|
|
token.Port = utils.MinIoPort
|
|
return
|
|
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
|
|
|
|
+}
|