Why does FileUpload not respect ->rules() ?
It seems that when specifying rules to a FileUpload field, it is not validated. Is that expected behaviour?
I know I probably should use
->acceptedFileTypes()
for this, but I actually want to validate the input on WOFF and WOFF2 font files.
Since acceptedFileTypes uses the front-end validator of Filepond, I can't use this, because browsers cannot resolve the correct mimetypes for these files...
So, I need to do some serverside validation. But how?Solution:Jump to solution
I've made PR for this: https://github.com/filamentphp/filament/pull/13814
GitHub
Add better mimetype support for FileUpload component by bbredewold ...
Description
This PR adds better front-end filetype validation to the FileUpload field.
The FileUpload field uses Filepond for uploading files.
When setting ->acceptedFileTypes() with the accepte...
7 Replies
Well, serverside validation seems to fail too...
...because Laravel's validator expects an actual File or UploadedFile. And all we get from FileUpload/Filepond is this:
["c97b1b35-ebc0-48bf-8258-bedbd02c123c" => "01J48ZGS4EMBSFS4Z3HSMPF1P4.woff2"]
So no validation of possible...
Validation of this should happen on upload and not on save. That's why
->rules()
probably don't work.
Hm, but interally Filament uses "mimetypes:{$types}";
, tooYes, internally is fine I guess. But when uploading a WOFF / WOFF2 file, the front-end validation always says that the uploaded file is of the wrong format, because my browser tells Filepond that it's mimetype is
null
...
See this exellent reply on SO: https://stackoverflow.com/a/77856904/2815350Stack Overflow
HTML input type="file" doesn't detect ttf, otf, or js, how do I cha...
HTML input type="file" event doesn't detect ttf, otf, or js, how do I change that? I would like to have mime types working from the start.
Maybe it's an idea to also accept 'extensions' instead of mimetypes. But the question is of Filepond will accept this.
I think it doesn't. Wanted to PR the same thing some time ago I think
Solution
I've made PR for this: https://github.com/filamentphp/filament/pull/13814
GitHub
Add better mimetype support for FileUpload component by bbredewold ...
Description
This PR adds better front-end filetype validation to the FileUpload field.
The FileUpload field uses Filepond for uploading files.
When setting ->acceptedFileTypes() with the accepte...
Nice, thanks!