CloudAnts commited on
Commit
422970b
·
1 Parent(s): 3c6631e
Files changed (1) hide show
  1. templates/index3.html +22 -3
templates/index3.html CHANGED
@@ -81,12 +81,31 @@
81
  const downloadCsvButton = document.getElementById('download-csv');
82
  const downloadImageButton = document.getElementById('download-image');
83
 
84
- // Listen for file selection and trigger page refresh
85
  invoiceInput.addEventListener('change', () => {
86
- // Reload the page when a file is selected
87
- window.location.reload();
 
 
 
 
88
  });
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  uploadBtn.addEventListener('click', () => {
91
  const file = invoiceInput.files[0];
92
  if (!file) return alert('Please select a file.');
 
81
  const downloadCsvButton = document.getElementById('download-csv');
82
  const downloadImageButton = document.getElementById('download-image');
83
 
84
+ // Listen for file selection and temporarily store it in localStorage
85
  invoiceInput.addEventListener('change', () => {
86
+ const file = invoiceInput.files[0];
87
+ if (file) {
88
+ const fileData = URL.createObjectURL(file);
89
+ localStorage.setItem('selectedFile', fileData);
90
+ window.location.reload(); // Trigger page reload
91
+ }
92
  });
93
 
94
+ // Check if a file is stored in localStorage upon page reload
95
+ window.onload = () => {
96
+ const storedFile = localStorage.getItem('selectedFile');
97
+ if (storedFile) {
98
+ // Reassign the selected file URL back to the file input
99
+ const fakeFile = new File([storedFile], "fakeFile.jpg", {type: "image/*"});
100
+ const dataTransfer = new DataTransfer();
101
+ dataTransfer.items.add(fakeFile);
102
+ invoiceInput.files = dataTransfer.files;
103
+
104
+ // Clean up localStorage
105
+ localStorage.removeItem('selectedFile');
106
+ }
107
+ };
108
+
109
  uploadBtn.addEventListener('click', () => {
110
  const file = invoiceInput.files[0];
111
  if (!file) return alert('Please select a file.');