© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
10 replies
Luiz

image upload using URL

Has anyone managed to create a way to upload media via URL to the https://filamentphp.com/plugins/filament-spatie-media-library plugin?

What I've managed to do so far is this:

Forms\Components\TextInput::make('url')
->label('URL')
->url()
->dehydrated(false)
->live(onBlur: true)
->suffixAction(
    Forms\Components\Actions\Action::make('downloadFile')
        ->icon('heroicon-m-arrow-down-tray')
        ->action(function ($record, Get $get, Set $set, $state, \Filament\Forms\Components\Component $component) {
            $contents = file_get_contents($state);
            $fileName = Str::ulid();
            $extension = pathinfo($state, PATHINFO_EXTENSION);
            $fileNameWithExtension = $fileName . '.' . $extension;
            $filePath = 'livewire-tmp/' . $fileNameWithExtension;

            // $SpatieMediaLibraryFileUpload = $component->getContainer()->getComponent(fn ($childComponent) => $childComponent->getName() === 'media');

            $storage = Storage::disk('local');

            $storage->put($filePath, $contents);

            $tempFile = TemporaryUploadedFile::createFromLivewire($fileNameWithExtension);

            $media = $get('media');
            $media[Str::uuid()->toString()] = $tempFile;

            $set('media', $media);

            $set('url', null);
        })
)
Forms\Components\TextInput::make('url')
->label('URL')
->url()
->dehydrated(false)
->live(onBlur: true)
->suffixAction(
    Forms\Components\Actions\Action::make('downloadFile')
        ->icon('heroicon-m-arrow-down-tray')
        ->action(function ($record, Get $get, Set $set, $state, \Filament\Forms\Components\Component $component) {
            $contents = file_get_contents($state);
            $fileName = Str::ulid();
            $extension = pathinfo($state, PATHINFO_EXTENSION);
            $fileNameWithExtension = $fileName . '.' . $extension;
            $filePath = 'livewire-tmp/' . $fileNameWithExtension;

            // $SpatieMediaLibraryFileUpload = $component->getContainer()->getComponent(fn ($childComponent) => $childComponent->getName() === 'media');

            $storage = Storage::disk('local');

            $storage->put($filePath, $contents);

            $tempFile = TemporaryUploadedFile::createFromLivewire($fileNameWithExtension);

            $media = $get('media');
            $media[Str::uuid()->toString()] = $tempFile;

            $set('media', $media);

            $set('url', null);
        })
)


However, nothing appears on the form and when I try to save it, an empty error occurs.
Filament
Spatie Media Library by Filament - Filament
Filament support for Spatie's Laravel Media Library package.
Spatie Media Library by Filament - Filament
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

Upload image from URL
FilamentFFilament / ❓┊help
2y ago
Upload Image/File from URL
FilamentFFilament / ❓┊help
3y ago
S3 image upload not getting full url?
FilamentFFilament / ❓┊help
2y ago
Change image upload url not to Storage
FilamentFFilament / ❓┊help
2y ago