u
This commit is contained in:
1 parent
b6415c0d65
commit
89aaef1d6b
29 files changed
+1118
-277
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package s3store
|
||||
|
||||
import (
|
||||
"allapp-go/internal/config"
|
||||
"context"
|
||||
"fmt"
|
||||
"mime/multipart"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
)
|
||||
|
||||
var S3Client *s3.Client
|
||||
var presignClient *s3.PresignClient
|
||||
var bucket string
|
||||
|
||||
func NewS3Client(cfg *config.Config) {
|
||||
credProvider := credentials.NewStaticCredentialsProvider(
|
||||
cfg.AwsS3.AccessKey,
|
||||
cfg.AwsS3.SecretKey,
|
||||
"",
|
||||
)
|
||||
|
||||
awsCfg := aws.Config{
|
||||
Region: cfg.AwsS3.Region,
|
||||
Credentials: credProvider,
|
||||
}
|
||||
|
||||
S3Client = s3.NewFromConfig(awsCfg, func(o *s3.Options) {
|
||||
o.BaseEndpoint = aws.String(cfg.AwsS3.Endpoint)
|
||||
o.UsePathStyle = true
|
||||
})
|
||||
|
||||
presignClient = s3.NewPresignClient(S3Client)
|
||||
|
||||
bucket = cfg.AwsS3.Bucket
|
||||
|
||||
fmt.Println("S3 client and Presign client initialized successfully!")
|
||||
}
|
||||
|
||||
func UploadToRustFS(ctx context.Context, key string, file multipart.File, size int64, contentType string) error {
|
||||
_, err := S3Client.PutObject(ctx, &s3.PutObjectInput{
|
||||
Bucket: aws.String(bucket),
|
||||
Key: aws.String(key),
|
||||
Body: file,
|
||||
ContentLength: aws.Int64(size),
|
||||
ContentType: aws.String(contentType),
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user