40 lines
906 B
Go
40 lines
906 B
Go
// minio.go
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"strings"
|
|
|
|
"github.com/minio/minio-go/v7"
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
)
|
|
|
|
func ConnectMinIO(cfg Config) (*minio.Client, error) {
|
|
minioClient, err := minio.New(cfg.MinioURL, &minio.Options{
|
|
Creds: credentials.NewStaticV4(cfg.MinioAccessKey, cfg.MinioSecretKey, ""),
|
|
Secure: true, // change to true if using https
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return minioClient, nil
|
|
}
|
|
|
|
func UploadToMinIO(ctx context.Context, client *minio.Client, bucket, path, mimeType string, data []byte, meta map[string]string) error {
|
|
|
|
key := strings.TrimPrefix(path, "/")
|
|
key = strings.TrimPrefix(key, "./")
|
|
|
|
log.Printf("Uploading to MinIO: %s", key)
|
|
_, err := client.PutObject(ctx, bucket, key,
|
|
NewBytesReader(data),
|
|
int64(len(data)),
|
|
minio.PutObjectOptions{
|
|
ContentType: mimeType,
|
|
UserMetadata: meta,
|
|
})
|
|
return err
|
|
}
|