diff --git a/runtimes/core/src/objects/mod.rs b/runtimes/core/src/objects/mod.rs index a537bd6f0b..4aab5601c0 100644 --- a/runtimes/core/src/objects/mod.rs +++ b/runtimes/core/src/objects/mod.rs @@ -496,17 +496,13 @@ fn escape_path(s: &str) -> Cow<'_, str> { /// Computes the public url given a base url, optional key prefix, and object name. fn public_url(base_url: String, key_prefix: Option<&str>, name: &str) -> String { let mut url = base_url; - if let Some(key_prefix) = key_prefix { - if !url.ends_with('/') { - url.push('/'); - } - url.push_str(&escape_path(key_prefix)); - } if !url.ends_with('/') { url.push('/'); } - + if let Some(key_prefix) = key_prefix { + url.push_str(&escape_path(key_prefix)); + } url.push_str(&escape_path(name)); url } diff --git a/runtimes/go/storage/objects/bucket.go b/runtimes/go/storage/objects/bucket.go index 6fa44d8196..92ddc98a45 100644 --- a/runtimes/go/storage/objects/bucket.go +++ b/runtimes/go/storage/objects/bucket.go @@ -143,6 +143,11 @@ func (b *Bucket) PublicURL(object string, options ...PublicURLOption) *url.URL { if !strings.HasSuffix(u.Path, "/") { u.Path += "/" } + + if b.runtimeCfg.KeyPrefix != "" { + u.Path += escape(b.runtimeCfg.KeyPrefix, encodePath) + } + u.Path += escape(object, encodePath) return &u