forked from siputzx/apis
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupload.html
More file actions
43 lines (38 loc) · 1.39 KB
/
upload.html
File metadata and controls
43 lines (38 loc) · 1.39 KB
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>Exonity CDN</title>
</head>
<body>
<i class="fa fa-upload" aria-hidden="true"></i>
<h1>Exonity Uploader</h1>
<form id="uploadForm">
<input type="file" id="fileInput" name="file" accept=".png,.jpg,.jpeg,.webp,.mp3,.mp4" required>
<button type="submit">Upload</button>
</form>
<p id="uploadResult"></p>
<script>
document.getElementById('uploadForm').addEventListener('submit', async (event) => {
event.preventDefault();
const formData = new FormData();
const fileInput = document.getElementById('fileInput');
formData.append('file', fileInput.files[0]);
try {
const response = await fetch('/cdn-upload', {
method: 'POST',
body: formData,
});
if (!response.ok) {
throw new Error('Upload failed');
}
const result = await response.json();
document.getElementById('uploadResult').textContent = `File uploaded successfully: ${result.url}`;
} catch (error) {
document.getElementById('uploadResult').textContent = error.message;
}
});
</script>
</body>
</html>