Skip to content

Commit f654d3c

Browse files
authored
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
1 parent 1b69b73 commit f654d3c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

plugin/storage/s3/s3.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"io"
8+
"net/url"
89
"strings"
910

1011
"github.com/aws/aws-sdk-go-v2/aws"
@@ -83,7 +84,11 @@ func (client *Client) UploadFile(ctx context.Context, filename string, fileType
8384
link := uploadOutput.Location
8485
// If url prefix is set, use it as the file link.
8586
if client.Config.URLPrefix != "" {
86-
link = fmt.Sprintf("%s/%s%s", client.Config.URLPrefix, filename, client.Config.URLSuffix)
87+
parts := strings.Split(filename, "/")
88+
for i := range parts {
89+
parts[i] = url.PathEscape(parts[i])
90+
}
91+
link = fmt.Sprintf("%s/%s%s", client.Config.URLPrefix, strings.Join(parts, "/"), client.Config.URLSuffix)
8792
}
8893
if link == "" {
8994
return "", errors.New("failed to get file link")

0 commit comments

Comments
 (0)