Simple file content validation #12

Merged
niat8586 merged 6 commits from simple-client-validation into develop 2025-02-04 11:32:33 +01:00
2 changed files with 18 additions and 1 deletions
Showing only changes of commit b948beaa2b - Show all commits

View File

@ -39,4 +39,20 @@ function deleteSelected() {
form.action = '/files/bulk-delete'; // Backend endpoint for bulk delete
form.submit();
}
}
// Handle file upload, check file type
function validateFile() {
const fileInput = document.getElementById('file');
const filePath = fileInput.value;
const allowedExtensions = /(\.mp3|\.mp4|\.mpeg|\.mpga|\.m4a|\.wav|\.webm)$/i;
const maxSize = 10 * 1024 * 1024; // 10 MB
if (!allowedExtensions.exec(filePath)) {
alert('Invalid file type. Please upload an audio file (mp3, mp4, mpeg, mpga, m4a, wav, webm).');
fileInput.value = '';
return false;
}
return true;
}

View File

@ -34,7 +34,8 @@
<form th:action="@{/files/upload}" method="post" enctype="multipart/form-data">
<div class="mb-3">
<label for="file" class="form-label">Choose File</label>
<input type="file" id="file" name="file" class="form-control" required>
<input type="file" id="file" name="file" class="form-control" required
accept=".mp3,.mp4,.mpeg,.mpga,.m4a,.wav,.webm" onchange="validateFile()">
</div>
<div class="mb-3">
<label for="language" class="form-label">Select Language</label>