need to tap into file upload save process

I have this action in my page class:
public function getHeaderActions(): array
{
return [
Action::make('upload')
->form([
FileUpload::make('upload')
->label('')
->multiple()
->preserveFilenames()
->acceptedFileTypes(['application/pdf'])
->maxSize(10000)
->storeFiles(false)
->storeFileNamesIn('original_file_name')
]),

...
public function getHeaderActions(): array
{
return [
Action::make('upload')
->form([
FileUpload::make('upload')
->label('')
->multiple()
->preserveFilenames()
->acceptedFileTypes(['application/pdf'])
->maxSize(10000)
->storeFiles(false)
->storeFileNamesIn('original_file_name')
]),

...
I want to be able to customize the data before saving it and I can't seem to tap into that. I've tried using the ->model(...) and ->statePath(...) methods. Also tried looking through the source code for the BaseFileUpload class and didn't see anything that looked like it might apply. I'm used to seeing something like mutateFormDataBeforeSave. The file is being saved to livewire-tmp, but nothing else happens and no error, which is strange because I'm not sure how it would be able to save to the database since I have other required fields it knows nothing about, which is why I need to customize the save process.
3 Replies
Jon Mason
Jon MasonOP9mo ago
Bump, any ideas here?
awcodes
awcodes9mo ago
You’re trying to hook in too late. You need to override the FileUpload component itself. Maybe some guidance at https://github.com/awcodes/filament-curator/blob/3.x/src/Components/Forms/Uploader.php
GitHub
filament-curator/src/Components/Forms/Uploader.php at 3.x · awcodes...
A media picker plugin for Filament Panels. Contribute to awcodes/filament-curator development by creating an account on GitHub.
Jon Mason
Jon MasonOP9mo ago
Ok thanks, I’ll check it ou After reviewing your code, I saw one place where you had done something like the below, so I tried it, and it ended up working for my use case. Leaving this here for anyone else who may run into this:
Action::make('upload')
->form([
FileUpload::make('upload')
->label('')
->multiple()
->preserveFilenames()
->acceptedFileTypes(['application/pdf'])
->maxSize(10000)
->storeFiles(false)
])->action(fn (array $data) => $this->saveFiles($data)),
Action::make('upload')
->form([
FileUpload::make('upload')
->label('')
->multiple()
->preserveFilenames()
->acceptedFileTypes(['application/pdf'])
->maxSize(10000)
->storeFiles(false)
])->action(fn (array $data) => $this->saveFiles($data)),
Want results from more Discord servers?
Add your server