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
pull/2832/head^2
Mudkip 1 year ago committed by GitHub
parent 1b69b73eb9
commit f654d3c90e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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

Loading…
Cancel
Save