-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
40 lines (38 loc) · 1.29 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple File Upload Test</title>
</head>
<body>
<form id="uploadForm" action="http://127.0.0.1:8028/process_pdf/" method="post" enctype="multipart/form-data" onsubmit="handleSubmit(event)">
<input type="file" name="file" id="fileInput" required />
<input type="submit" value="Upload File" />
</form>
<script>
function handleSubmit(event) {
event.preventDefault(); // This will prevent the default form submission
const form = document.getElementById('uploadForm');
const formData = new FormData(form);
// Perform the fetch inside this function without reloading the page
fetch(form.action, {
method: 'POST',
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error(`Server returned ${response.status}: ${response.statusText}`);
}
return response.blob();
})
.then(blob => {
// Handle the response blob (e.g., download the file)
})
.catch(error => {
console.error('Upload failed:', error);
});
}
</script>
</body>
</html>