-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtes.html
More file actions
53 lines (44 loc) · 1.45 KB
/
tes.html
File metadata and controls
53 lines (44 loc) · 1.45 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
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Upload MP3</title>
</head>
<body>
<h2>Upload MP3 File</h2>
<form id="uploadForm">
<input type="file" id="mp3Input" accept=".mp3" required />
<button type="submit">Upload</button>
</form>
<p id="status"></p>
<script>
document.getElementById("uploadForm").addEventListener("submit", async function (e) {
e.preventDefault();
const fileInput = document.getElementById("mp3Input");
const file = fileInput.files[0];
if (!file || !file.name.endsWith(".mp3")) {
document.getElementById("status").textContent = "❌ Pilih file .mp3 terlebih dahulu!";
return;
}
const formData = new FormData();
formData.append("file", file);
try {
const response = await fetch("http://localhost:4000/api/upload", {
method: "POST",
body: formData
});
const result = await response.json();
if (response.ok) {
document.getElementById("status").textContent = `✅ Upload berhasil: ${result.file}`;
} else {
document.getElementById("status").textContent = `❌ Upload gagal: ${result.error}`;
}
} catch (err) {
document.getElementById("status").textContent = "❌ Terjadi kesalahan saat upload.";
console.error(err);
}
});
</script>
</body>
</html>