blob: 5f12414e664b860e2907de8bbf0c717bd5acf6c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import { Base64 } from "js-base64";
export function base64(blob: Blob | string): Promise<string> {
if (typeof blob === "string") {
return Promise.resolve(Base64.encode(blob));
}
return new Promise<string>((resolve) => {
const reader = new FileReader();
reader.onload = function () {
resolve((reader.result as string).replace(/^data:.*;base64,/, ""));
};
reader.readAsDataURL(blob);
});
}
|