`Forms\Components\FileUpload` image preview

In create view, I want a image preview, so user can preview what they are going to upload. In edit view, I want a preview, so that user can see what they'll replace. How do you do that?
4 Replies
Dennis Koch
Dennis Koch3mo ago
Images are instantly uploaded. I don't think there is a way to preview them properly with the default features.
atabegruslan
atabegruslan3mo ago
True. It actually previews automatically. I just had a bug So, I realized, for preview to work, the saved image need to follow Filament's way - as storage/app/public/CODED-NAME.png. I wasnt seeing the preview because I had a custom save method and I didnt save the image with the coded-name. (I probably missed a few other things too) So now my question now becomes: where is that save-image method that Filament uses by default? Actually never mind. I totally figured this out. Have to 1/ save like storage/app/public/CODED-NAME.png 2/ and store into DB as CODED-NAME.png, not path/CODED-NAME.png nor url/CODED-NAME.png problem solved
Vp
Vp3mo ago
Hi @atabegruslan good to know that you solved this, but I think you don't understand how laravel file upload works.. You need to do storage:link and you don't have to save like your solution.. (saved to storage path is correct.. but you need to symlink to your public directory) And Filament (by default) upload publicly to your storage disk defined in config (https://filamentphp.com/docs/3.x/forms/fields/file-upload#configuring-the-storage-disk-and-directory), you can still use ->directory('img-directory') and store in DB like img-directory/sfd79dnsdfs.png And one important: you need to put APP_URL correctly in order to preview images correctly
atabegruslan
atabegruslan3mo ago
True. I did the storage:link part. Thank you for the rest of the info
Want results from more Discord servers?
Add your server