Custom FileUpload state validation after upload

I am working a a project where I need to get the TempUploadedFile from FileUpload and extract information from the image (using external API to read information) and make sure the document code is valid. If not I want to show user an error message and fail the upload (red color on FileUpload will be good indicator).
This FileUpload field is located in a Form inside a FilamentPage.

I have tried using afterStateUpdated(fn(FileUpload $component, Set $set) => $this->extractInformation($component, $set)) to call a function for all the logic and within it I tried using _uploadErrored as well as throwing ValidationException directly but neither of them worked.


How can I achieve this?
Than you for your help.
Was this page helpful?