Sonata media bundle - get pdf file by name or change filename on update Sonata media bundle - get pdf file by name or change filename on update symfony symfony

Sonata media bundle - get pdf file by name or change filename on update


use this in your Twig so you can download it with its name:

{{ path('sonata_media_download', {'id': (your media object here|sonata_urlsafeid)}) }}

To see it without download, I'm searching for that , I'll be back if I find something.

Good luck!


If you want get public URL for file in PHP-code, you can use something like this (code from my Application\Sonata\MediaBundle\Helper\MediaHelper)

public function getPublicUrl(Media $media, $format = 'reference'){    if (!$media) {        return '';    }    /** @var ImageProvider $provider */    $provider = $this->container->get($media->getProviderName());    $format = $provider->getFormatName($media, $format);    return $provider->generatePublicUrl($media, $format);}

If you need link in twig, you can find special helper in SonataMedia official docs (I forgot name of helper).