From 0ea2f79d45b301fcd660efc894469a99b2239bf6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 8 Sep 2021 10:10:51 +0200 Subject: Safer image preview --- client/src/root-helpers/images.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 client/src/root-helpers/images.ts (limited to 'client/src/root-helpers/images.ts') diff --git a/client/src/root-helpers/images.ts b/client/src/root-helpers/images.ts new file mode 100644 index 000000000..fb229ce6d --- /dev/null +++ b/client/src/root-helpers/images.ts @@ -0,0 +1,13 @@ +function imageToDataURL (input: File | Blob) { + return new Promise(res => { + const reader = new FileReader() + + reader.onerror = err => console.error('Cannot read input file.', err) + reader.onloadend = () => res(reader.result as string) + reader.readAsDataURL(input) + }) +} + +export { + imageToDataURL +} -- cgit v1.2.3