mirror of
https://github.com/usememos/memos.git
synced 2025-10-06 12:26:29 +08:00
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
This commit is contained in:
parent
1b69b73eb9
commit
f654d3c90e
1 changed files with 6 additions and 1 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"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
|
link := uploadOutput.Location
|
||||||
// If url prefix is set, use it as the file link.
|
// If url prefix is set, use it as the file link.
|
||||||
if client.Config.URLPrefix != "" {
|
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 == "" {
|
if link == "" {
|
||||||
return "", errors.New("failed to get file link")
|
return "", errors.New("failed to get file link")
|
||||||
|
|
Loading…
Add table
Reference in a new issue