-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathup.html
43 lines (39 loc) · 1.5 KB
/
up.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
41
42
43
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Upload Test</title>
</head>
<body>
<h1>Upload a File</h1>
<form id="uploadForm" enctype="multipart/form-data" method="post">
<label for="file">Choose a file:</label>
<input type="file" id="file" name="file" required>
<button type="submit">Upload</button>
</form>
<p id="responseMessage"></p>
<script>
document.getElementById('uploadForm').addEventListener('submit', async (event) => {
event.preventDefault();
const formData = new FormData();
const fileInput = document.getElementById('file');
formData.append('file', fileInput.files[0]);
try {
const response = await fetch('http://localhost:3000/upload', {
method: 'POST',
body: formData
});
const result = await response.json();
if (response.ok) {
document.getElementById('responseMessage').textContent = `File uploaded successfully! Hash: ${result.hash}`;
} else {
document.getElementById('responseMessage').textContent = `Error: ${result.message}`;
}
} catch (error) {
document.getElementById('responseMessage').textContent = `Error: ${error.message}`;
}
});
</script>
</body>
</html>