Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
RingedPlanet authored Oct 13, 2024
1 parent f22f4c2 commit 7ceab1b
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions file_upload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!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>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f7f7f7;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

.upload-container {
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
}

input[type="file"] {
padding: 10px;
margin: 20px 0;
}

.upload-container h2 {
margin-bottom: 20px;
}

button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}

button:hover {
background-color: #45a049;
}
</style>
</head>

<body>
<div class="upload-container">
<h2>Upload Your File</h2>
<input type="file" id="fileInput" />
<br />
<button onclick="uploadFile()">Upload</button>
<p id="status"></p>
</div>

<script>
async function uploadFile() {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
const status = document.getElementById('status');

if (file) {
const formData = new FormData();
formData.append('file', file);

try {
const response = await fetch('/upload', {
method: 'POST',
body: formData,
});

if (response.ok) {
const result = await response.json();
status.textContent = 'File uploaded successfully: ' + result.filename;
} else {
status.textContent = 'Upload failed!';
}
} catch (error) {
console.error('Error:', error);
status.textContent = 'Error during upload!';
}
} else {
status.textContent = 'No file selected!';
}
}
</script>
</body>

</html>

0 comments on commit 7ceab1b

Please sign in to comment.