Versions stable (inachevée mais prête à un déploiement en prod)
This commit is contained in:
21
src/main/java/dev/lions/utils/FileValidator.java
Normal file
21
src/main/java/dev/lions/utils/FileValidator.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package dev.lions.utils;
|
||||
|
||||
import dev.lions.exceptions.FileUploadException;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import org.primefaces.model.file.UploadedFile;
|
||||
|
||||
/**
|
||||
* Utilitaire pour la validation des fichiers téléchargés.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class FileValidator {
|
||||
public void validateFile(UploadedFile file, String acceptedTypes, long maxSize) {
|
||||
if (file.getSize() > maxSize) {
|
||||
throw new FileUploadException("Le fichier dépasse la taille maximale autorisée.");
|
||||
}
|
||||
|
||||
if (!acceptedTypes.contains(file.getContentType())) {
|
||||
throw new FileUploadException("Type de fichier non autorisé.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user