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); +}