aboutsummaryrefslogtreecommitdiff
path: root/src/utils/files.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/files.ts')
-rw-r--r--src/utils/files.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/utils/files.ts b/src/utils/files.ts
new file mode 100644
index 0000000..98c342c
--- /dev/null
+++ b/src/utils/files.ts
@@ -0,0 +1,15 @@
+export const getLocalFileUrl = (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);
+ });
+};