|
@@ -4,6 +4,7 @@ import (
|
|
|
"context"
|
|
|
"errors"
|
|
|
"eta/eta_api/utils"
|
|
|
+ "fmt"
|
|
|
"github.com/minio/minio-go/v7"
|
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
|
"log"
|
|
@@ -347,3 +348,55 @@ func UploadMinIoToDir(filename, filePath, uploadDir, fileDir string) (string, er
|
|
|
path = utils.MinIoImghost + path
|
|
|
return path, err
|
|
|
}
|
|
|
+
|
|
|
+func UploadImgToMinIoTest(fileName, filePath string) (string, error) {
|
|
|
+ ctx := context.Background()
|
|
|
+ endpoint := utils.Endpoint
|
|
|
+ accessKeyID := utils.AccessKeyId
|
|
|
+ secretAccessKey := utils.AccessKeySecret
|
|
|
+ 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 {
|
|
|
+ log.Fatalln(err)
|
|
|
+ return "1", err
|
|
|
+ }
|
|
|
+ bucketName := utils.Bucketname
|
|
|
+ // Check to see if we already own this bucket (which happens if you run this twice)
|
|
|
+
|
|
|
+ buckets, e := minioClient.ListBuckets(ctx)
|
|
|
+ if e != nil {
|
|
|
+ fmt.Println("ListBuckets: ", e.Error())
|
|
|
+ return "", e
|
|
|
+ }
|
|
|
+ for k := range buckets {
|
|
|
+ fmt.Println(k)
|
|
|
+ }
|
|
|
+
|
|
|
+ exists, errBucketExists := minioClient.BucketExists(ctx, bucketName)
|
|
|
+ fmt.Println("exists: ", exists)
|
|
|
+ fmt.Println("errBucketExists: ", errBucketExists)
|
|
|
+ if errBucketExists == nil && exists {
|
|
|
+ log.Printf("We already own %s\n", bucketName)
|
|
|
+ } else {
|
|
|
+ log.Fatalln(err)
|
|
|
+ return "2", err
|
|
|
+ }
|
|
|
+ path := utils.UploadDir + time.Now().Format("200601/20060102/")
|
|
|
+ path += fileName
|
|
|
+ // Upload the zip file with FPutObject
|
|
|
+ //contentType := "application/xlsx"
|
|
|
+ _, err = minioClient.FPutObject(ctx, bucketName, path, filePath, minio.PutObjectOptions{})
|
|
|
+ if err != nil {
|
|
|
+ log.Fatalln(err)
|
|
|
+ return "3", err
|
|
|
+ }
|
|
|
+
|
|
|
+ path = utils.Imghost + path
|
|
|
+ return path, err
|
|
|
+}
|