37 lines
No EOL
1 KiB
HTML
37 lines
No EOL
1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>File upload</title>
|
|
</head>
|
|
|
|
<body>
|
|
<input type="file" id="file"><br>
|
|
<button id="upload-btn">Upload</button>
|
|
<br>
|
|
<p id="status-spn"></p>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/axios@0.20.0/dist/axios.min.js"></script>
|
|
<script>
|
|
document.getElementById('upload-btn').addEventListener('click', async () => {
|
|
const file = document.getElementById('file');
|
|
if (file.files.length) {
|
|
console.log(file.files[0]);
|
|
|
|
const formData = new FormData();
|
|
formData.append('file', file.files[0]);
|
|
try {
|
|
let response = await axios.post('/api/upload', formData);
|
|
const chart = response.data;
|
|
document.getElementById('status-spn').innerHTML = `<b>${chart.artist} - ${chart.title}</b> has been uploaded!`;
|
|
} catch (error) {
|
|
document.getElementById('status-spn').innerText = `Error: ${error.response.data}`;
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html> |