dmitrybubyakin / nova-medialibrary-field

Laravel Nova field for managing the Spatie media library
MIT License
264 stars 61 forks source link

when viewing (eye icon) cannot get Media Conversions and Media Download URL to work with S3 #109

Open vesper8 opened 3 years ago

vesper8 commented 3 years ago

I am using S3 with private links. I have gotten the previews and downloads to work by using

                ->previewUsing(function (Media $media) {
                    return $media->getTemporaryUrl(Carbon::now()->addMinutes(5), 'optimized');
                })
                ->downloadUsing(function (Media $media) {
                    return $media->getTemporaryUrl(Carbon::now()->addMinutes(5), 'optimized');
                })

However when clicking on the eye icon to view the media. The Media Conversions are not signed so they end up being broken images. And also the Media Download URL is also not signed and so is also not working should you decide to copy/paste it

Do you know how I can get these to also work with ->getTemporaryUrl() ?

dmitrybubyakin commented 3 years ago

@vesper8 Hi. Have a look https://spatie.be/docs/laravel-medialibrary/v9/advanced-usage/generating-custom-urls

Or you can extend this field if you don't want to use custom image generator.

If you extend this class you also need to use custom fields instead of default ones. https://github.com/dmitrybubyakin/nova-medialibrary-field#fields

vesper8 commented 3 years ago

@dmitrybubyakin Thank you for the links. It's all a bit confusing though, since S3 with private links is a fairly popular usage case it would be nice if you could add an example to the readme that has everything working

vesper8 commented 3 years ago

I was already using a custom url generator so I just added this conditional to it and it works

    public function getUrl(): string
    {
        if (substr($_SERVER['REQUEST_URI'], 0, strlen('/nova')) === '/nova') {
            $url = $this->getTemporaryUrl(\Carbon\Carbon::now()->addDays(1));
        } else {
            $url = $this->getDisk()->url($this->getPathRelativeToRoot());
        }

        $url = $this->versionUrl($url);

        return $url;
    }
dmitrybubyakin commented 3 years ago

@vesper8 Nice solution!