How can I add a client side error message to FileUpload?

When uploading a file that is either not the correct file type, or larger than 2 megabytes, the light gray "x" icon jiggles, but I'd like to add a client side error message as to why the error occurred. It seems that `->validationMessages()" does not do this. How can I add friednly messages specific to each validation?
FileUpload::make('image')
->maxSize(2048)
->acceptedFileTypes(['image/png', 'image/jpeg']);
FileUpload::make('image')
->maxSize(2048)
->acceptedFileTypes(['image/png', 'image/jpeg']);
2 Replies
BuddhaNature
BuddhaNatureOP5d ago
This doesn't address my problem. I can perform all of the server side validations fine and issue custom messages accordingly. In my code example, if a user adds an image larger that 2MB, the validation kicks in on the client side and the file is not uploaded. In the article above, which is good, but not applicable, any file above 2MB would be uploaded and then validated on the server side. What I'm looking to accomplish is to present a message to the user when they attempt to upload a file larger than 2MB on the client side. As is, the validation just causes the "X" button to jiggle which is not obvious.
Want results from more Discord servers?
Add your server