nova-medialibrary-field
nova-medialibrary-field copied to clipboard
Image preview not displayed after upload when using previewUsing()
I’m using a cropped version of the uploaded image in ->previewUsing('cropped').
The problem is that shortly after uploading the image, the preview is not shown. Maybe because it is not available at this time?
If so, maybe you need to refresh the previews after the conversions are ready …
@JonathanDoelan You can do something like this:
public function previewUsingThumbnailIfGenerated(): callable
{
return function (Media $media) {
return $media->hasGeneratedConversion('thumbnail')
? $media->getFullUrl('thumbnail')
: $media->getFullUrl();
};
}
And then:
Medialibrary::make('Thumbnail', 'thumbnail')->previewUsing(
$this->previewUsingThumbnailIfGenerated()
)
@dmitrybubyakin Thank you! Yes, it works!
Why not making this the default behaviour?
@JonathanDoelan I'll add this to docs.