From b85cfe3e3410ca0976539edf4fe54d0d4d07018f Mon Sep 17 00:00:00 2001 From: TristanEDU Date: Tue, 9 Sep 2025 12:40:03 +0000 Subject: [PATCH] Add file input handling and image type validation in app.js --- src/app.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/app.js b/src/app.js index b2095e7..c555e28 100644 --- a/src/app.js +++ b/src/app.js @@ -3,6 +3,15 @@ const imagePreview = document.getElementById("imagePreview"); const textEditor = document.getElementById("textEditor"); const ocrButton = document.getElementById("btnRunOCR"); const exportButton = document.getElementById("btnExport"); +const imageTypes = [ + "image/jpeg", + "image/png", + "image/gif", + "image/bmp", + "image/webp", + "image/svg+xml", + "image/tiff", +]; console.log( "DOM wired:", @@ -12,3 +21,14 @@ console.log( ocrButton, exportButton ); + +fileInput.onchange = () => { + const selectedFiles = [...fileInput.files]; + for (const f of selectedFiles) { + console.log(f); + if (imageTypes.includes(f.type)) { + console.log("Image Type = " + f.type); + imagePreview.src = URL.createObjectURL(f); + } + } +};