Files
WebApp/src/app/connect/api/file-encoding.ts
T

13 lines
439 B
TypeScript

/** Base64 of a File's bytes, for JSON endpoints that carry a file. */
export function fileToBase64(file: Blob): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
const dataUrl = reader.result as string;
resolve(dataUrl.slice(dataUrl.indexOf(',') + 1));
};
reader.onerror = () => reject(reader.error);
reader.readAsDataURL(file);
});
}