From 7368927c77b3937876fde8cbc0752d6bab555148 Mon Sep 17 00:00:00 2001 From: Phillip Date: Wed, 7 Jun 2023 18:33:31 +0300 Subject: [PATCH] use only one instance of fileReader --- .../plugins/core/components/qdn-action-encryption.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/plugins/core/components/qdn-action-encryption.js b/plugins/plugins/core/components/qdn-action-encryption.js index 98b26c67..e9bd4f1d 100644 --- a/plugins/plugins/core/components/qdn-action-encryption.js +++ b/plugins/plugins/core/components/qdn-action-encryption.js @@ -2,20 +2,29 @@ import nacl from '../../../../crypto/api/deps/nacl-fast.js' import ed2curve from '../../../../crypto/api/deps/ed2curve.js' +let reader = new FileReader(); export const fileToBase64 = (file) => new Promise((resolve, reject) => { - const reader = new FileReader(); + if (!reader) { + reader = new FileReader(); + } reader.readAsDataURL(file); reader.onload = () => { const dataUrl = reader.result; if (typeof dataUrl === "string") { const base64String = dataUrl.split(',')[1]; + reader.onload = null; + reader.onerror = null; resolve(base64String); } else { + reader.onload = null; + reader.onerror = null; reject(new Error('Invalid data URL')); } }; reader.onerror = (error) => { + reader.onload = null; + reader.onerror = null; reject(error); }; });