From f654d3c90e676de214fe8ceae0f9d04673cad44d Mon Sep 17 00:00:00 2001 From: Mudkip <518069+mudkipme@users.noreply.github.com> Date: Wed, 24 Jan 2024 11:28:26 +0800 Subject: [PATCH] fix: encode filename when using url prefix for resources (#2829) * fix: encode filename when using url prefix for resources * fix: only encode the last parts of filename * fix: encode all parts in filepath --- plugin/storage/s3/s3.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/storage/s3/s3.go b/plugin/storage/s3/s3.go index e0a17d4a..8618fd62 100644 --- a/plugin/storage/s3/s3.go +++ b/plugin/storage/s3/s3.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "net/url" "strings" "github.com/aws/aws-sdk-go-v2/aws" @@ -83,7 +84,11 @@ func (client *Client) UploadFile(ctx context.Context, filename string, fileType link := uploadOutput.Location // If url prefix is set, use it as the file link. if client.Config.URLPrefix != "" { - link = fmt.Sprintf("%s/%s%s", client.Config.URLPrefix, filename, client.Config.URLSuffix) + parts := strings.Split(filename, "/") + for i := range parts { + parts[i] = url.PathEscape(parts[i]) + } + link = fmt.Sprintf("%s/%s%s", client.Config.URLPrefix, strings.Join(parts, "/"), client.Config.URLSuffix) } if link == "" { return "", errors.New("failed to get file link")