Skip to content

Commit e7f1313

Browse files
Add base64 encoding to download-image
1 parent d875bdf commit e7f1313

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/sdk.geometry-api-sdk-v2/src/UtilsApi.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,18 @@ export class UtilsApi extends BaseAPI {
193193
return this.download(url, options) as any;
194194
} else {
195195
// All other source URLs are called via the download-image endpoint
196-
return new AssetsApi(this.configuration).downloadImage(sessionId, url, options);
196+
197+
// Use a universal base64 encoder for browser and Node.js environments
198+
const encodedUrl =
199+
typeof window !== 'undefined' && window.btoa
200+
? window.btoa(
201+
encodeURIComponent(url).replace(/%([0-9A-F]{2})/g, (_, p1) =>
202+
String.fromCharCode(parseInt(p1, 16))
203+
)
204+
)
205+
: Buffer.from(url, 'utf-8').toString('base64');
206+
207+
return new AssetsApi(this.configuration).downloadImage(sessionId, encodedUrl, options);
197208
}
198209
}
199210

0 commit comments

Comments
 (0)