nova-medialibrary-field icon indicating copy to clipboard operation
nova-medialibrary-field copied to clipboard

Image preview not displayed after upload when using previewUsing()

Open ghost opened this issue 4 years ago • 3 comments

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 …

ghost avatar Dec 01 '20 08:12 ghost

@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 avatar Dec 02 '20 16:12 dmitrybubyakin

@dmitrybubyakin Thank you! Yes, it works!

Why not making this the default behaviour?

JonathanDoelan avatar Dec 02 '20 17:12 JonathanDoelan

@JonathanDoelan I'll add this to docs.

dmitrybubyakin avatar Dec 03 '20 09:12 dmitrybubyakin