koel/resources/assets/js/composables/useFileReader.ts
2024-10-14 00:37:01 +07:00

12 lines
327 B
TypeScript

export const useFileReader = () => {
const reader = new FileReader()
const readAsDataUrl = (file: File, callback: (result: string) => void | Promise<void>) => {
reader.addEventListener('load', async () => await callback(reader.result as string))
reader.readAsDataURL(file)
}
return {
readAsDataUrl,
}
}