I’m currently facing an issue where all file types are being allowed for upload in a process instance, and I need to restrict it so that only PDF files can be uploaded.
Is there a way to configure this restriction or enforce only PDF uploads in the process instance?
Any advice or suggestions on how to achieve this would be greatly appreciated!
The accept=".pdf" attribute ensures only PDF files are selectable.
this will help on FE side for you.
public class FileValidationDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
byte[] fileContent = (byte[]) execution.getVariable("uploadedFile");
String fileName = (String) execution.getVariable("fileName");
// Check file extension
if (!fileName.endsWith(".pdf")) {
throw new IllegalArgumentException("Only PDF files are allowed!");
}
// Optionally, check file signature (magic number) for stricter validation
String magicNumber = Base64.getEncoder().encodeToString(fileContent).substring(0, 4);
if (!magicNumber.equals("25504446")) { // PDF Magic Number: %PDF
throw new IllegalArgumentException("Uploaded file is not a valid PDF!");
}
}
}
In your BPMN model, include a condition or validation step where the process checks the uploaded file type. This can be done using an exclusive gateway or a service task.