feat: add support for s3 path (#1233)

* add support for path

* fix typo and switch positions with Path and Bucket

* using path method instead of string concatenation
This commit is contained in:
Alex Zhao
2023-03-04 07:59:44 +08:00
committed by GitHub
parent e062c9b4a7
commit 9d4bb5b3af
5 changed files with 18 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"path"
"github.com/aws/aws-sdk-go-v2/aws"
s3config "github.com/aws/aws-sdk-go-v2/config"
@ -18,6 +19,7 @@ type Config struct {
SecretKey string
Bucket string
EndPoint string
Path string
Region string
URLPrefix string
}
@ -55,7 +57,7 @@ func (client *Client) UploadFile(ctx context.Context, filename string, fileType
uploader := manager.NewUploader(client.Client)
uploadOutput, err := uploader.Upload(ctx, &awss3.PutObjectInput{
Bucket: aws.String(client.Config.Bucket),
Key: aws.String(filename),
Key: aws.String(path.Join(client.Config.Path, filename)),
Body: src,
ContentType: aws.String(fileType),
ACL: types.ObjectCannedACL(*aws.String("public-read")),