From 1a0e0808b05208dad3392d0e3292aa0438cfd4af Mon Sep 17 00:00:00 2001 From: sksadjad Date: Thu, 8 Feb 2024 23:45:08 +0100 Subject: [PATCH] fix: changed the image-size usage to handle uint8array --- packages/ssi-sdk-core/src/utils/image.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/ssi-sdk-core/src/utils/image.ts b/packages/ssi-sdk-core/src/utils/image.ts index 8ca322a39..b01764202 100644 --- a/packages/ssi-sdk-core/src/utils/image.ts +++ b/packages/ssi-sdk-core/src/utils/image.ts @@ -10,8 +10,8 @@ type SizeCalculationResult = { } export const getImageMediaType = async (base64: string): Promise => { - const buffer: Buffer = Buffer.from(base64, 'base64') - const result: SizeCalculationResult = imageSize(buffer) + const int8Array: Uint8Array = base64ToUint8Array(base64) + const result: SizeCalculationResult = imageSize(int8Array) switch (result.type) { case undefined: @@ -48,3 +48,9 @@ export const downloadImage = async (url: string): Promise => { contentType: contentType || undefined, } } + +const base64ToUint8Array = (base64: string): Uint8Array => { + const base64WithoutPrefix: string = base64.split(',').pop()!; + const buffer = Buffer.from(base64WithoutPrefix, 'base64'); + return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength); +}