F
Filamentβ€’2mo ago
Lloyd

Image Postprocessing

Folks, how do I get the path of an uploaded image? (I want to edit this image by sending it to an API, then replace it)
FileUpload::make('image')
->afterStateUpdated(function ($state) {
$path = $state->getPath();
log('state', [$path]);
})
FileUpload::make('image')
->afterStateUpdated(function ($state) {
$path = $state->getPath();
log('state', [$path]);
})
This just returns storage/app/livewire-tmp, and not the actual path of the uploaded image 😦 Thanks in advance! Also, would it be better to do this after the form is submit, then replace it? I'm not sure..
5 Replies
Alex'R
Alex'Rβ€’2mo ago
Hi, your file has not yet been uploaded, it is in the temporary files. It's up to you to determine the path in which you want to store it. You can, however, retrieve the file name.
Lloyd
LloydOPβ€’2mo ago
Thank you @Alex'R. How can I send it to an API after it has been submit/upload, to fix it? Is that the correct event?
Lloyd
LloydOPβ€’2mo ago
Awesome, thanks! I've got image as a key in:
protected function mutateFormDataBeforeSave(array $data): array
{
log('form_data',[$data]);
protected function mutateFormDataBeforeSave(array $data): array
{
log('form_data',[$data]);
how do I resolve the image path to an actual path? it simply gives me for example:
{"image":"01JATDC7YWHQP7NMN2MDMNN45D.png"
{"image":"01JATDC7YWHQP7NMN2MDMNN45D.png"
Alex'R
Alex'Rβ€’2mo ago
depends of your storage configuration explore your storage folder and you get the path with storage_path() method if you want the file is public, you should use public as FILESYSTEM_DISK in your .env and use php artisan storage:link, instead you can use publicly
Want results from more Discord servers?
Add your server