© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•5mo ago•
4 replies
keiron

Show preview of already saved image in FileUpload

I am trying to show my already saved image in the FileUpload component. I have two issues:

1. I have to put the URL in an array otherwise I get
foreach() argument must be of type array|object, string given
foreach() argument must be of type array|object, string given
- is this normal?
2. It does not load my image.

I have stripped out everything and hardcoded the URL for simplicity. In this database only the file name is stored, so I will need to modify it anyway to have the full path.

<?php

namespace App\Filament\Pages;

use App\Models\Photo;
use Filament\Forms\Components\FileUpload;
use Filament\Pages\Page;
use Filament\Schemas\Concerns\InteractsWithSchemas;
use Filament\Schemas\Contracts\HasSchemas;
use Filament\Schemas\Schema;
use Livewire\Attributes\Url;

class VetPhoto extends Page implements HasSchemas
{
    use InteractsWithSchemas;

    #[Url]
    public ?int $photoId = null;

    protected string $view = 'filament.pages.vet-photo';

    public Photo $photo;

    public ?array $data = [];

    public function mount(): void
    {
        $this->data['file'] = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTfHlcmASZgNOAA0mtIwob78oSLwGP1PybjDQ&s';
    }

    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                FileUpload::make('file')->image(),
            ])
            ->statePath('data');
    }
}
<?php

namespace App\Filament\Pages;

use App\Models\Photo;
use Filament\Forms\Components\FileUpload;
use Filament\Pages\Page;
use Filament\Schemas\Concerns\InteractsWithSchemas;
use Filament\Schemas\Contracts\HasSchemas;
use Filament\Schemas\Schema;
use Livewire\Attributes\Url;

class VetPhoto extends Page implements HasSchemas
{
    use InteractsWithSchemas;

    #[Url]
    public ?int $photoId = null;

    protected string $view = 'filament.pages.vet-photo';

    public Photo $photo;

    public ?array $data = [];

    public function mount(): void
    {
        $this->data['file'] = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTfHlcmASZgNOAA0mtIwob78oSLwGP1PybjDQ&s';
    }

    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                FileUpload::make('file')->image(),
            ])
            ->statePath('data');
    }
}
Solution
Fixed it:

<?php

namespace App\Filament\Pages;

use App\Models\Photo;
use Filament\Forms\Components\FileUpload;
use Filament\Pages\Page;
use Filament\Schemas\Concerns\InteractsWithSchemas;
use Filament\Schemas\Contracts\HasSchemas;
use Filament\Schemas\Schema;
use Livewire\Attributes\Url;

class VetPhoto extends Page implements HasSchemas
{
    use InteractsWithSchemas;

    #[Url]
    public ?int $photoId = null;

    protected string $view = 'filament.pages.vet-photo';

    public Photo $photo;

    public ?array $data = [];

    public function mount(): void
    {
        $this->data['file'] = ['data/photos/mobile/204671357_1752175651.jpg'];
    }

    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                FileUpload::make('file')
                ->image()
                ->imageEditor()
                ->disk('s3'),
            ])
            ->statePath('data');
    }
}
<?php

namespace App\Filament\Pages;

use App\Models\Photo;
use Filament\Forms\Components\FileUpload;
use Filament\Pages\Page;
use Filament\Schemas\Concerns\InteractsWithSchemas;
use Filament\Schemas\Contracts\HasSchemas;
use Filament\Schemas\Schema;
use Livewire\Attributes\Url;

class VetPhoto extends Page implements HasSchemas
{
    use InteractsWithSchemas;

    #[Url]
    public ?int $photoId = null;

    protected string $view = 'filament.pages.vet-photo';

    public Photo $photo;

    public ?array $data = [];

    public function mount(): void
    {
        $this->data['file'] = ['data/photos/mobile/204671357_1752175651.jpg'];
    }

    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                FileUpload::make('file')
                ->image()
                ->imageEditor()
                ->disk('s3'),
            ])
            ->statePath('data');
    }
}
Jump to solution
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

`Forms\Components\FileUpload` image preview
FilamentFFilament / ❓┊help
2y ago
Image Preview after $set in FileUpload field
FilamentFFilament / ❓┊help
12mo ago
Image preview not loading using FileUpload
FilamentFFilament / ❓┊help
17mo ago