I would like to show a PDF file that have been uploaded with gaufrette. I get the URI from Doctrine ("wine_information/1-wine_information.pdf").
But the root directory can be different if it is on local or remote (Amazon s3).
I tried to use the filter twig of liip_imagine to use the CacheManager.php and the method getBrowserPath but I can't create one because I have no filter to apply on my PDF. it's only for images.
and now I found this solution : https://github.com/KnpLabs/Gaufrette/issues/332#issuecomment-159849533
UploaderService.php
public function getPath($filePath)
{
$fileSystem = $this->container->get('gaufrette.' . $this->env . self::MEDIA_FILESYSTEM);
$adapter = $fileSystem->getAdapter();
$reflection = new \ReflectionClass($adapter);
$directory = $reflection->getProperty('directory');
$directory->setAccessible(true);
return $directory->getValue($adapter) . $filePath;
}
When it's on local it return the following path :
/home/company/projectName/web/media/wine_information/1-wine_information.pdf
but I would like to have a real link to set in my <a href="" target="_blanck"></a>
I found the solution. I have made a twig filter to get the path of the file uploaded with gaufrette. Solutions used for Amazon S3 and local.
app\config\services.yml
html.twig
AppBundle\Resources\config\services.yml
AppBundle\Twig\AppFilterExtension.php