blob: 1469804f3aac42f6172710cccd6110ff111546a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
export default (file: File): Promise<string> => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.addEventListener('load', () => {
if (typeof reader.result === 'string') resolve(reader.result);
}, false);
reader.addEventListener('error', () => {
reject(new Error('Error reading the file'));
}, false);
if (file) reader.readAsDataURL(file);
});
};
|