mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Move function to util
This commit is contained in:
parent
f872f604f9
commit
eccfd5316d
2 changed files with 17 additions and 14 deletions
15
src/utils/file.ts
Normal file
15
src/utils/file.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* 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);
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue