From 082a02f0e77ed3b9d6dae8d6626805daf687dd9d Mon Sep 17 00:00:00 2001 From: Billy Lo Date: Mon, 1 Nov 2021 10:43:20 -0400 Subject: [PATCH] add checking so only PDFs are saved locally image files can be too big for local storage to handle. (better to have reliability) --- components/Form.tsx | 5 +++-- pages/index.tsx | 2 +- public/displayLocallySavedItem.html | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/components/Form.tsx b/components/Form.tsx index eff1d3e..8124c30 100644 --- a/components/Form.tsx +++ b/components/Form.tsx @@ -161,10 +161,11 @@ function Form(): JSX.Element { async function storeFileToLocalStorageBase64(key: string, file: File) { - if (window.localStorage) { + if (window.localStorage && file.type.includes('application/pdf')) { // https://stackoverflow.com/a/56738510/2789065 + console.log('storing buffer ' + file.type); const buffer = Buffer.from(await new Response(file).arrayBuffer()); let dataUrl = `data:${file.type};base64,${buffer.toString("base64")}`; localStorage.setItem(key, dataUrl); @@ -177,7 +178,7 @@ function Form(): JSX.Element { const payload = await getPayloadBodyFromFile(file); payload.dataUrl = "receipt"; - console.log(file2); + console.log(file); if (file2) { payload.extraUrl = file2.name; diff --git a/pages/index.tsx b/pages/index.tsx index 6cfebd4..3cda772 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -111,7 +111,7 @@ function Index(): JSX.Element {