* Build a fallback object URL for when the SDK omits `Location` on multipart * completion. For a custom `S3_CONFIG.endpoint` it matches the configured * addressing mode — path-style for MinIO/Ceph (`forcePathStyle`), virtual-hosted * (bucket as a subdomain) for R2 and friends. Falls back to the A
(bucket: string, region: string, key: string)
| 440 | * keys containing spaces or reserved characters still yield a valid URL. |
| 441 | */ |
| 442 | function buildObjectFallbackUrl(bucket: string, region: string, key: string): string { |
| 443 | const encodedKey = key |
| 444 | .split('/') |
| 445 | .map((segment) => encodeURIComponent(segment)) |
| 446 | .join('/') |
| 447 | if (S3_CONFIG.endpoint) { |
| 448 | const base = S3_CONFIG.endpoint.replace(/\/+$/, '') |
| 449 | if (S3_CONFIG.forcePathStyle) { |
| 450 | return `${base}/${bucket}/${encodedKey}` |
| 451 | } |
| 452 | const url = new URL(base) |
| 453 | url.hostname = `${bucket}.${url.hostname}` |
| 454 | return `${url.origin}/${encodedKey}` |
| 455 | } |
| 456 | return `https://${bucket}.s3.${region}.amazonaws.com/${encodedKey}` |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * Complete multipart upload for S3 |
no test coverage detected