Get image from S3 without full path in sql column
I am adapting a pre-existing custom admin to filamentphp, now I have images on an S3 structured like this:
cdn.blabla.ext/namesite/gallery/{{$game_id}}/{{$image}}
With the old admin I used:
To visualize it I would simply use:
But how does it work with filament?
In the documentation I read:
>The column in the database must contain the path to the image, relative to the root directory of its storage disk.
Currently in the database I saved ONLY the name of the image, if I understand correctly I in the database should save:
image = namesite/gallery/123/nameimage.png
can I bypass this?
3 Replies
If you weren't using the dynamic $gameId, you could have used scoped storage and not had to change anything else. But unfortunately, having that dynamic path makes things a little trickier to migrate.
Honestly, your best bet is to migrate your existing data so the database field includes the full path. Then going forward you can use a closure in a directory() method on the FileUpload element to set the path to include the game ID.
Depending how your data is structured, you could probably do the migration with a single MySQL query by hand, with something like ...
Practice the query using new_image. Then you can rename as appropriate once it's working.
Then in the FileUpoad, something like ...
Thank you very much @cheesegrits !
Penso che sia conveniente scrivere l'url completo dell'immagine nella query, tuttavia non capisco come inserire il "namesite" nel filesystem... I would not like to save that query paths as:
Penso che sia conveniente scrivere l'url completo dell'immagine nella query, tuttavia non capisco come inserire il "namesite" nel filesystem... I would not like to save that query paths as:
"namesite/gallery/1487/starfield-40586589.jpg"
, I would like to save only "gallery/1487/starfield-40586589.jpg"
, and get the namesite from the filesystem, but I don't understand how to set it up.... If I put it in the AWS_URL, it doesn't read it....If you just want to always have namesite/ prepended to the path (and it doesn't change, it's always the same string) you can use a scoped disk.
https://laravel.com/docs/10.x/filesystem#scoped-and-read-only-filesystems
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.