1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/utils/file.ts

16 lines
493 B
TypeScript
Raw Normal View History

2023-09-27 16:42:31 +02:00
/**
* Reads and returns the file encoded in base64
*/
export function readFileAsBase64(file: File): Promise<string> {
return new Promise(function (resolve, reject) {
const reader = new FileReader();
reader.onload = (e) => {
// Split by a comma to remove the url: prefix
const data = (e.target?.result as string)?.split?.(',')[1];
resolve(data);
};
reader.onerror = reject;
reader.readAsDataURL(file);
});
}