FileUpload field validation passes on upload but fails on submit

Hello Filament people! Working on my first project and have a curious problem with a FileUpload field. I'm allowing upload of a favicon and am validating using
->acceptedFileTypes([
'image/vnd.microsoft.icon',
])
->acceptedFileTypes([
'image/vnd.microsoft.icon',
])
This works just fine for the upload task - so I believe the mime type is correct. When the form is submitted, it fails with a validation.mimetypes error. Using a ->image() validation works fine. Not sure what's going on here - I'd prefer to restrict to just .ico files. filament forms v3.2.100, Ubuntu 2204/ PHP8.3 host
Solution:
yeah I've been thinking that might be the workaround. I can see a hint that it's getting turned into an octet stream during the submission process. But I've got over it for now with ->rules(['extensions:ico,png']) (although that doesn't work on the client side)...
Jump to solution
11 Replies
toeknee
toeknee4mo ago
Can you provide the whole FileUpload Field.
darrenm
darrenmOP4mo ago
FileUpload::make('faviconSrc')
->disk(config('platform.storage.disk'))
->directory('partner/'.$tenant->id.'/faviconSrc')
->acceptedFileTypes([
'image/vnd.microsoft.icon',
])
->imagePreviewHeight('50')
->maxSize(20)
->maxFiles(1)
->label(__('Favicon'))
->panelLayout('compact')
->required(),
FileUpload::make('faviconSrc')
->disk(config('platform.storage.disk'))
->directory('partner/'.$tenant->id.'/faviconSrc')
->acceptedFileTypes([
'image/vnd.microsoft.icon',
])
->imagePreviewHeight('50')
->maxSize(20)
->maxFiles(1)
->label(__('Favicon'))
->panelLayout('compact')
->required(),
toeknee
toeknee4mo ago
Whats the full error? Does it say the mime type failure/where it was triggered? try:
->acceptedFileTypes([
'image/vnd.microsoft.icon',
'image/x-icon'
])
->acceptedFileTypes([
'image/vnd.microsoft.icon',
'image/x-icon'
])
too
markmyers
markmyers4mo ago
@darrenm Does the file get created in the livewire-tmp directory?
toeknee
toeknee4mo ago
It should do if memory serves me right
markmyers
markmyers4mo ago
Yeah it should, just trying to see if its similar to my issue here: https://discord.com/channels/883083792112300104/1275513064086569022
darrenm
darrenmOP4mo ago
yes "The favicon field must be a file of type: image/vnd.microsoft.icon, image/x-icon"
toeknee
toeknee4mo ago
Customise the validation rule and dump what the mime type is
markmyers
markmyers4mo ago
@toeknee how would you dump the mime type in filament form?
toeknee
toeknee4mo ago
Write a custom validation rule which handles it
Solution
darrenm
darrenm4mo ago
yeah I've been thinking that might be the workaround. I can see a hint that it's getting turned into an octet stream during the submission process. But I've got over it for now with ->rules(['extensions:ico,png']) (although that doesn't work on the client side)
Want results from more Discord servers?
Add your server