Why does FileUpload not respect ->rules() ?

It seems that when specifying rules to a FileUpload field, it is not validated. Is that expected behaviour?
FileUpload::make('csv_file')
->label(__('CSV File'))
->rules(['mimes:csv,txt']) // This allows images just fine
FileUpload::make('csv_file')
->label(__('CSV File'))
->rules(['mimes:csv,txt']) // This allows images just fine
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:
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...
Jump to solution
7 Replies
The Milkman
The Milkman4mo ago
Well, serverside validation seems to fail too...
$this->validate([
'formData.font_woff2_filename' => 'mimetypes:font/woff2,application/font-woff2',
'formData.font_woff_filename' => 'mimetypes:font/woff,application/font-woff',
]);
$this->validate([
'formData.font_woff2_filename' => 'mimetypes:font/woff2,application/font-woff2',
'formData.font_woff_filename' => 'mimetypes:font/woff,application/font-woff',
]);
...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...
Dennis Koch
Dennis Koch4mo ago
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}";, too
The Milkman
The Milkman4mo ago
Yes, 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/2815350
Stack 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.
The Milkman
The Milkman4mo ago
Maybe it's an idea to also accept 'extensions' instead of mimetypes. But the question is of Filepond will accept this.
Dennis Koch
Dennis Koch4mo ago
I think it doesn't. Wanted to PR the same thing some time ago I think
Solution
The Milkman
The Milkman3mo ago
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...
Dennis Koch
Dennis Koch3mo ago
Nice, thanks!
Want results from more Discord servers?
Add your server