Upload image from URL

I am trying to upload a file from url to FileUpload field. Has anyone tried something like this before?

I am able to upload the file locally, then save the path to db and then reset the FileUpload field state with new path.

But I dont want to save it DB after downlaoding the file from url. I just want to pass it to FileUpload field, so that user can see a preview.

Here is what i am trying. Everything works, file also saves correctly on submit and also previews after submit.

But it does not preview unless you submit it.

so wondering if there is a way to tell Filament to preview it.

Forms\Components\FileUpload::make('featured_image')->hintAction(
  Filament\Forms\Components\Actions\Action::make('url_uploader')
    ->form([TextInput::make('url')->label('Image URL')])
    ->action(function (Set $set, Component $livewire, array $data) {
        $filePath = UrlUploadedFile::createFromUrl($data['url'])
            ->store('livewire-tmp', ['disk' => 'local']);
        $filePath = explode('/', $filePath)[1];

        $file = TemporaryUploadedFile::createFromLivewire($filePath);

        $set($livewire->mountedFormComponentActionsComponents[0], [$file], true);
    }),
)
Was this page helpful?