© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
9 replies
rabol

How do I get the file in a upload action

on a resource page I have an action:

Tables\Actions\Action::make('import')
                    ->form([
                        Forms\Components\FileUpload::make('file'),
                    ])
                    ->label('')
                    ->tooltip('Import')
                    ->icon('heroicon-o-folder-open')
                    ->action('import'),
Tables\Actions\Action::make('import')
                    ->form([
                        Forms\Components\FileUpload::make('file'),
                    ])
                    ->label('')
                    ->tooltip('Import')
                    ->icon('heroicon-o-folder-open')
                    ->action('import'),


shows a modal, one can upload a file and it call my 'import' method.

But... what parameters do I get in my method?

I would lige to get the current record and then the fileupload so that I can 'import' the data in this case

public function import($record, $file)
    {

        dd($record, $file);
    }
public function import($record, $file)
    {

        dd($record, $file);
    }


Does not work
Solution
Here is the solution

                Tables\Actions\Action::make('import')
                    ->form([
                        FileUpload::make('file')
                            ->label('')
                            ->acceptedFileTypes(['application/json', 'json'])
                            ->imagePreviewHeight('250')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set, TemporaryUploadedFile $state) {
                                $set('fileRealPath', $state->getRealPath());
                            }),
                        Hidden::make('fileRealPath'),
                    ])
                    ->label('')
                    ->tooltip('Import')
                    ->icon('heroicon-o-folder-open')
                    ->action('import'),
                Tables\Actions\Action::make('import')
                    ->form([
                        FileUpload::make('file')
                            ->label('')
                            ->acceptedFileTypes(['application/json', 'json'])
                            ->imagePreviewHeight('250')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set, TemporaryUploadedFile $state) {
                                $set('fileRealPath', $state->getRealPath());
                            }),
                        Hidden::make('fileRealPath'),
                    ])
                    ->label('')
                    ->tooltip('Import')
                    ->icon('heroicon-o-folder-open')
                    ->action('import'),


The trick is to store the realpath in a hidden input
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

File upload in actions
FilamentFFilament / ❓┊help
3y ago
How to get file in action form
FilamentFFilament / ❓┊help
2y ago
How do i access raw file in action modal
FilamentFFilament / ❓┊help
3y ago