msc4039 support b64 in addition to blob file download

This commit is contained in:
Valere
2026-03-26 15:29:51 +01:00
parent 40fdef89eb
commit 8f38ecac2e

View File

@@ -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;
}