koel/resources/assets/js/utils/fileReader.ts

12 lines
335 B
TypeScript
Raw Normal View History

2022-04-15 14:24:30 +00:00
export const fileReader = {
/**
* Read a File into a binary string
*/
readAsDataUrl: (file: Blob) => new Promise<string>((resolve, reject): void => {
const reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = () => resolve(<string>reader.result)
reader.onerror = error => reject(error)
})
}