Temporary files are never moved

I am using Filament's Wizard for a multi-step form. On step 1, the model is created. On the last step, some files are uploaded. Those files make it to the livewire-tmp directory, but they are never moved after the form is submitted.
Step::make('File Attachments')
->schema(function () {
$fields = [];

foreach (Installer::$onboardingFiles as $field => $options) {
$fields[$field] =
Section::make([
FileUpload::make($field)
->label($options['title'])
->storeFileNamesIn($field . '_name')
->directory(fn () => 'installers/' . $this->installer->id . '/documents/' . $options['directory'])
->getUploadedFileNameForStorageUsing(fn (TemporaryUploadedFile $file): string => $options['filename'] . '.' . $file->guessExtension())
->disk('s3')
->hidden(fn (Get $get): bool => $get($field . '_toggle')),
])
]);
}

return $fields;
}),
])
->submitAction(new HtmlString(Blade::render(<<<BLADE
<x-filament::button
type="submit"
size="sm"
wire:click="create"
>
Submit
</x-filament::button>
BLADE)))
]);
}

public function create(): void
{
$this->updateModel(5);
}
Step::make('File Attachments')
->schema(function () {
$fields = [];

foreach (Installer::$onboardingFiles as $field => $options) {
$fields[$field] =
Section::make([
FileUpload::make($field)
->label($options['title'])
->storeFileNamesIn($field . '_name')
->directory(fn () => 'installers/' . $this->installer->id . '/documents/' . $options['directory'])
->getUploadedFileNameForStorageUsing(fn (TemporaryUploadedFile $file): string => $options['filename'] . '.' . $file->guessExtension())
->disk('s3')
->hidden(fn (Get $get): bool => $get($field . '_toggle')),
])
]);
}

return $fields;
}),
])
->submitAction(new HtmlString(Blade::render(<<<BLADE
<x-filament::button
type="submit"
size="sm"
wire:click="create"
>
Submit
</x-filament::button>
BLADE)))
]);
}

public function create(): void
{
$this->updateModel(5);
}
The files are not renamed or moved. I feel like I probably need to call a method to process the files, but the documentation doesn't mention it.
11 Replies
awcodes
awcodes6mo ago
Iirc you have to use ->visibility(‘private’) in order to upload to s3
christhompsontldr
christhompsontldrOP6mo ago
Thanks. I just tried that and it also didn't work.
->directory('installers')
->disk('public')
->directory('installers')
->disk('public')
Even this doesn't work, so I think I need to call some Filament method(s) to process tmp uploads
awcodes
awcodes6mo ago
Saving the form is what moves and processes the temp files. Maybe it has something to do with saving the model up front instead of on form submission. You can try a FileUpload in a non wizard context to help troubleshoot.
christhompsontldr
christhompsontldrOP6mo ago
It works as expected in a non-wizard, non-model-created-on-first step setup. How does Filament know create() on my Livewire component is being called?
awcodes
awcodes6mo ago
It’s the default form submit action. A wizard is just one big form that just shows and hides its respective form fields.
christhompsontldr
christhompsontldrOP6mo ago
I'm confused. What is "the default form submit action?" https://filamentphp.com/docs/3.x/forms/layout/wizard#rendering-a-submit-button-on-the-last-step mentions wiring up a Livewire method to handle form submission, which is what I have done.
awcodes
awcodes6mo ago
Wiring it up depends on if you are using the wizard with panels or in a standalone livewire component.
christhompsontldr
christhompsontldrOP6mo ago
Standalone livewire component is what I'm using.
awcodes
awcodes6mo ago
Are you calling $this->form->getState() in your save / submit for the form? GetState() will run the validations and process the form data including file uploads.
christhompsontldr
christhompsontldrOP6mo ago
Ah, no, we stopped using it because it did something automagical that was breaking our form. I can't remember what, specifically. Ok, switched from getRawState() to getState() and the file upload and moving all works! Thanks. Tacking on to this. The reason we don't use getState() is because it runs the validations for all steps, so if there are required fields on step 4, but step 1 is being completed, it fails because it's trying to tell the use that a field on step 4 (which they haven't gotten to yet) is required.
awcodes
awcodes6mo ago
Yea. I get it, so you’ll need to dive into the getState and see how it’s applying the file handling and replicate that for the individual step. You’re trying to use the wizard as a multiple form instead of steps in a form so it going to require a more granular custom approach.
Want results from more Discord servers?
Add your server