33 lines
870 B
JavaScript
Raw Normal View History

2024-08-26 18:37:38 +05:30
document.getElementById("uploadButton").addEventListener("click", async () => {
const fileInput = document.getElementById("fileInput");
const files = Array.from(fileInput.files);
if (files.length === 0) {
alert("Please select some files first.");
return;
}
const formData = new FormData();
formData.append("bounty_id", 7);
files.forEach((file) => {
formData.append("files", file); // Append each file to FormData
});
try {
const response = await fetch("http://localhost:5000/submit-solution", {
method: "POST",
body: formData,
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
const data = await response.json();
console.log("Upload successful:", data);
} catch (error) {
console.error("Error uploading files:", error);
}
});