diff --git a/object/storage.go b/object/storage.go index 2096e0254..bac488f43 100644 --- a/object/storage.go +++ b/object/storage.go @@ -17,6 +17,7 @@ package object import ( "bytes" "fmt" + "net/url" "strings" "github.com/casdoor/casdoor/conf" @@ -42,8 +43,19 @@ func getProviderEndpoint(provider *Provider) string { return endpoint } +func escapePath(path string) string { + tokens := strings.Split(path, "/") + if len(tokens) > 0 { + tokens[len(tokens)-1] = url.QueryEscape(tokens[len(tokens)-1]) + } + + res := strings.Join(tokens, "/") + return res +} + func getUploadFileUrl(provider *Provider, fullFilePath string, hasTimestamp bool) (string, string) { - objectKey := util.UrlJoin(util.GetUrlPath(provider.Domain), fullFilePath) + escapedPath := escapePath(fullFilePath) + objectKey := util.UrlJoin(util.GetUrlPath(provider.Domain), escapedPath) host := "" if provider.Type != "Local File System" {