F
Filamentβ€’3w ago
rjcc

Get chosen files on FileUpload (multiple) after state updated.

Hi guys. I want to get the chosen files to be uploaded (temporary files) after state updated. It actually works on single file upload but when it comes to multiple, it didn't work out. Can you help me solve this? Thanks in advance. FileUpload::make('file') ->label('Documents:') ->validationAttribute('documents') ->acceptedFileTypes(['application/pdf']) ->required() ->openable() ->multiple() ->downloadable(false) ->deletable(false) ->reorderable() ->appendFiles() ->preserveFilenames() ->uploadingMessage('Uploading Documents...') ->directory(fn ($get) => $get('number')) // Directory based on 'number' field ->reactive() ->afterStateUpdated(function (TemporaryUploadedFile $state, callable $set) { //dd($state); $set('filePreviewData', $state->getClientOriginalName()); }), ViewField::make('filePreviewData') ->view('livewire.file-preview-modal') ->visible(function ($get) { if ($get('file') !== null && !empty($get('file'))) { return $get('file'); } })
5 Replies
toeknee
toekneeβ€’3w ago
You'll likely need to get the state and loop I suspect? what is dd on state?
rjcc
rjccβ€’3w ago
When I dd(), it only have the first file that was chosen although it was an array and I have to loop it to get like the realPath(). May I ask if I deleted a file that was chosen, does the state update automatically?
toeknee
toekneeβ€’3w ago
I would assume so... but it would need testing as I didn't create the field πŸ˜‰
rjcc
rjccβ€’3w ago
As per my tests, it didn't update the $state. 😦 Per my tests, when I deleted ALL the files that was chosen before, it will update the state. But if I only deleted one file, it won't.
toeknee
toekneeβ€’3w ago
You could modify: deleteUploadedFileUsing get the file and the process the parent and try and trigger an update
Want results from more Discord servers?
Add your server