From 8f38ecac2efc82036b3b0ab58bf85ff46ddfe252 Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 26 Mar 2026 15:29:51 +0100 Subject: [PATCH] msc4039 support b64 in addition to blob file download --- src/Avatar.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Avatar.tsx b/src/Avatar.tsx index d0cb243c..46e2bf21 100644 --- a/src/Avatar.tsx +++ b/src/Avatar.tsx @@ -181,9 +181,16 @@ async function getAvatarFromWidgetAPI( const file = response.file; // element-web sends a Blob, and the MSC4039 is considering changing the spec to strictly Blob, so only handling that - if (!(file instanceof Blob)) { - throw new Error("Downloaded file is not a Blob"); + if (file instanceof Blob) { + return file; + } else if (typeof file === "string") { + // it is a base64 string + const bytes = Uint8Array.from(atob(file), (c) => + c.charCodeAt(0), + ); + return new Blob([bytes]); } + throw new Error("Downloaded file format is not supported: " + typeof file + ""); + - return file; }