Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 1x 3x 3x 3x 3x 3x 3x 3x | /**
* Read a file object and invoke a callback function with the data url of this file
* @param file The file to read
* @param callback the callback to invoke with data url of the file.
* If fail to read, dataUrl will be null
*/
export function readFile(file: File, callback: (dataUrl: string | null) => void) {
try {
Eif (file) {
const reader = new FileReader();
reader.onload = () => {
callback(reader.result as string);
};
reader.onerror = () => {
callback(null);
};
reader.readAsDataURL(file);
}
} catch {
callback(null);
}
}
|