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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 1 deletions

View File

@ -12,6 +12,7 @@ type StorageConfig struct {
type StorageS3Config struct {
EndPoint string `json:"endPoint"`
Path string `json:"path"`
Region string `json:"region"`
AccessKey string `json:"accessKey"`
SecretKey string `json:"secretKey"`

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")),

View File

@ -139,6 +139,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
AccessKey: s3Config.AccessKey,
SecretKey: s3Config.SecretKey,
EndPoint: s3Config.EndPoint,
Path: s3Config.Path,
Region: s3Config.Region,
Bucket: s3Config.Bucket,
URLPrefix: s3Config.URLPrefix,

View File

@ -21,6 +21,7 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
region: "",
accessKey: "",
secretKey: "",
path: "",
bucket: "",
urlPrefix: "",
});
@ -181,6 +182,17 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
onChange={(e) => setPartialS3Config({ bucket: e.target.value })}
fullWidth
/>
<Typography className="!mb-1" level="body2">
Path
<span className="text-sm text-gray-400 ml-1">(Storage Path)</span>
</Typography>
<Input
className="mb-2"
placeholder="Path"
value={s3Config.path}
onChange={(e) => setPartialS3Config({ path: e.target.value })}
fullWidth
/>
<Typography className="!mb-1" level="body2">
URLPrefix
<span className="text-sm text-gray-400 ml-1">(Custom URL prefix; Optional)</span>

View File

@ -7,6 +7,7 @@ interface StorageS3Config {
region: string;
accessKey: string;
secretKey: string;
path: string;
bucket: string;
urlPrefix: string;
}