Simple file content validation
Instead of enforcing we are "warning" that the outcome for the selected file may not work as expected
This commit is contained in:
parent
b948beaa2b
commit
448c1e9d6b
src/main/resources
@ -45,13 +45,14 @@ function deleteSelected() {
|
|||||||
function validateFile() {
|
function validateFile() {
|
||||||
const fileInput = document.getElementById('file');
|
const fileInput = document.getElementById('file');
|
||||||
const filePath = fileInput.value;
|
const filePath = fileInput.value;
|
||||||
const allowedExtensions = /(\.mp3|\.mp4|\.mpeg|\.mpga|\.m4a|\.wav|\.webm)$/i;
|
const allowedExtensions = /(\.mp3|\.mp4|\.mpeg|\.mpga|\.m4a|\.wav|\.webm|\.ogg)$/i;
|
||||||
const maxSize = 10 * 1024 * 1024; // 10 MB
|
const maxSize = 10 * 1024 * 1024; // 10 MB
|
||||||
|
|
||||||
if (!allowedExtensions.exec(filePath)) {
|
if (!allowedExtensions.exec(filePath)) {
|
||||||
alert('Invalid file type. Please upload an audio file (mp3, mp4, mpeg, mpga, m4a, wav, webm).');
|
alert('File type is not one of the recommended types. We recommend using MP3, MP4, MPEG, MPGA, M4A, WAV, WEBM, OGG.\n' +
|
||||||
fileInput.value = '';
|
'We can not guarantee that other file types will work as expected.');
|
||||||
return false;
|
fileInput.value = filePath;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="file" class="form-label">Choose File</label>
|
<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()">
|
accept=".mp3,.mp4,.mpeg,.mpga,.m4a,.wav,.webm,.ogg" onchange="validateFile()">
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="language" class="form-label">Select Language</label>
|
<label for="language" class="form-label">Select Language</label>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user