Implement file upload validation (types and size limit)
This commit is contained in:
parent
21be798e30
commit
6e27b9e8cb
2 changed files with 21 additions and 2 deletions
|
|
@ -25,8 +25,9 @@
|
||||||
name="file"
|
name="file"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
style="display: none"
|
style="display: none"
|
||||||
(change)="onFileChange($event)"
|
(change)="handleFileSelection($event)"
|
||||||
multiple
|
multiple
|
||||||
|
accept=".png,.gif,.jpg,.jpeg,.pdf,.doc,.docx,.mp3,.wav,.mp4,.wmv,.avi"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<textarea
|
<textarea
|
||||||
|
|
|
||||||
|
|
@ -169,10 +169,28 @@ export class ChatMsgBoxComponent {
|
||||||
'video/x-ms-wmv': 4,
|
'video/x-ms-wmv': 4,
|
||||||
'video/avi': 4,
|
'video/avi': 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.getFileIcons[fileTypeMap[fileInfo.type] ?? 5];
|
return this.getFileIcons[fileTypeMap[fileInfo.type] ?? 5];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the file selection and checks whether file types and file sizes meet the requirements.
|
||||||
|
* @param {Event} event - The file input change event that contains the uploaded files.
|
||||||
|
*/
|
||||||
|
handleFileSelection(event: any) {
|
||||||
|
const files = event.target.files;
|
||||||
|
const maxSize = 1 * 1024 * 1024; // 3 MB in Bytes
|
||||||
|
|
||||||
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
const file = files[i];
|
||||||
|
|
||||||
|
// Prüfen der Dateigröße
|
||||||
|
if (file.size > maxSize) {
|
||||||
|
this.fileSizeError = false;
|
||||||
|
}
|
||||||
|
this.fileSizeError = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the selected file.
|
* Deletes the selected file.
|
||||||
* @param file The file to be deleted.
|
* @param file The file to be deleted.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue