How to access file(s) before submitting a form

In a table header action I have form that I want it to interact with an AI service. The form entails an file upload and an action right below it. When the action us trigger the file uploaded will be sent to the service and then use the response to fill other read only section of the form and now the form can be submitted. I have tried using the $get() to access the file in the temporary storage but I am getting an associative array with a random key every time I uploaded an image. Kindly assist, thank you.
5 Replies
toeknee
toeknee7mo ago
you can use $this->form->getState but it will upload the files and process them for your use. Otherwise you can use $this->form->getRawState() and handle the file manually.
lawre17
lawre17OP7mo ago
Nope this works only when the form is submitted, if I decide to use javascript I have no Idea how I can access the file from filamanet but ill what I can do
awcodes
awcodes7mo ago
If it’s only one image you could always use the Arr facade to grab the first item. Arr::first($get(‘image_field’))
lawre17
lawre17OP7mo ago
I tried this too and all I get is an Instance of \Livewire\TemporaryFIleUpoad where I can see all I want but accessing the properties is problem.
awcodes
awcodes7mo ago
Yea, well in livewire all FileUpload are TemporaryFileUploads until the form is saved. Saving the form is what persists the file upload and moves it from temp storage to storage.
Want results from more Discord servers?
Add your server