88 lines
No EOL
1.7 KiB
HTML
88 lines
No EOL
1.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Sube musica</title>
|
|
<style>
|
|
#drop_zone
|
|
{
|
|
width: 600px;
|
|
height: 500px;
|
|
border: 2px solid #ccc;
|
|
border-radius: 10px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
text-align: center;
|
|
color: #777;
|
|
font-size: 1.2em;
|
|
margin-bottom: 20px;
|
|
background-color: #fff;
|
|
transition: background-color 0.3s, border-color 0.3s;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div
|
|
id="drop_zone"
|
|
ondrop="dropHandler(event);"
|
|
ondragover="dragOverHandler(event);"
|
|
>
|
|
</div>
|
|
|
|
<script>
|
|
const dropZone = document.getElementById('drop_zone');
|
|
|
|
function dropHandler(ev)
|
|
{
|
|
ev.preventDefault();
|
|
|
|
let file_to_upload;
|
|
|
|
if (ev.dataTransfer.items) {
|
|
[...ev.dataTransfer.items].forEach((item, i) =>
|
|
{
|
|
if (item.kind === "file")
|
|
file_to_upload = item.getAsFile();
|
|
});
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
[...ev.dataTransfer.files].forEach((file, i) =>
|
|
{
|
|
file_to_upload = file;
|
|
});
|
|
}
|
|
|
|
uploadFile(file_to_upload);
|
|
}
|
|
|
|
function dragOverHandler(ev)
|
|
{
|
|
ev.preventDefault();
|
|
}
|
|
|
|
|
|
function uploadFile(file)
|
|
{
|
|
|
|
const url = '/';
|
|
|
|
const formData = new FormData();
|
|
|
|
formData.append('uploadedFile', file, file.name);
|
|
|
|
fetch(url,
|
|
{
|
|
method: 'POST',
|
|
body: formData,
|
|
})
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html> |