|
@@ -1,9 +1,11 @@
|
|
// Select the file input element
|
|
// Select the file input element
|
|
const fileInput = document.querySelector('input[type="file"]');
|
|
const fileInput = document.querySelector('input[type="file"]');
|
|
|
|
|
|
|
|
+let filesToUpload = [];
|
|
|
|
+
|
|
// Add a 'change' event listener to the file input element
|
|
// Add a 'change' event listener to the file input element
|
|
fileInput.addEventListener("change", (e) => {
|
|
fileInput.addEventListener("change", (e) => {
|
|
- console.log(e.target.files);
|
|
|
|
|
|
+ console.log(e.target.files);
|
|
// Get the selected files from the event target
|
|
// Get the selected files from the event target
|
|
const files = e.target.files;
|
|
const files = e.target.files;
|
|
|
|
|
|
@@ -23,4 +25,24 @@ fileInput.addEventListener("change", (e) => {
|
|
// Append the row to the file-list table
|
|
// Append the row to the file-list table
|
|
fileList.appendChild(row);
|
|
fileList.appendChild(row);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ uploadFiles(files);
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+const uploadFiles = (files) => {
|
|
|
|
+ const formData = new FormData();
|
|
|
|
+
|
|
|
|
+ for (let i = 0; i < files.length; i++) {
|
|
|
|
+ formData.append("files", files[i], files[i].name);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fetch("/upload", {
|
|
|
|
+ method: "POST",
|
|
|
|
+ body: formData,
|
|
|
|
+ })
|
|
|
|
+ .then((res) => res.json())
|
|
|
|
+ .then((data) => {
|
|
|
|
+ console.log(data);
|
|
|
|
+ })
|
|
|
|
+ .catch((err) => console.log(err));
|
|
|
|
+};
|