Skip to content

Commit cf4129f

Browse files
committed
fix(storage): percent-encode object key in multipart fallback URL
buildObjectFallbackUrl built the object URL from a raw key. Keys with spaces or reserved characters (and the pre-existing AWS branch) would produce a structurally invalid location. Encode the key per path segment (preserving '/' separators) across all branches (AWS, custom path-style, virtual-hosted).
1 parent 85942a5 commit cf4129f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

apps/sim/lib/uploads/providers/s3/client.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,18 +394,22 @@ export async function getS3MultipartPartUrls(
394394
* addressing mode — path-style for MinIO/Ceph (`forcePathStyle`), virtual-hosted
395395
* (bucket as a subdomain) for R2 and friends. Falls back to the AWS
396396
* virtual-hosted host when no custom endpoint is set.
397+
*
398+
* The key is percent-encoded per path segment (preserving `/` separators) so
399+
* keys containing spaces or reserved characters still yield a valid URL.
397400
*/
398401
function buildObjectFallbackUrl(bucket: string, region: string, key: string): string {
402+
const encodedKey = key.split('/').map(encodeURIComponent).join('/')
399403
if (S3_CONFIG.endpoint) {
400404
const base = S3_CONFIG.endpoint.replace(/\/+$/, '')
401405
if (S3_CONFIG.forcePathStyle) {
402-
return `${base}/${bucket}/${key}`
406+
return `${base}/${bucket}/${encodedKey}`
403407
}
404408
const url = new URL(base)
405409
url.hostname = `${bucket}.${url.hostname}`
406-
return `${url.origin}/${key}`
410+
return `${url.origin}/${encodedKey}`
407411
}
408-
return `https://${bucket}.s3.${region}.amazonaws.com/${key}`
412+
return `https://${bucket}.s3.${region}.amazonaws.com/${encodedKey}`
409413
}
410414

411415
/**

0 commit comments

Comments
 (0)