I am trying to give direct access to uploaded files only for logged in users in my website for security concerns. I tried this configuration but it seems to be working on download image.
This is my Twig file code where I am showing the image.
{% if(req.media!='') %}
<a href="{% path req.media, 'reference' %}"
data-fancybox class="fancybox">
<img src="{% path (req.media), 'reference' %}" alt="" width="70px"
height="70px"/>
</a>
{% endif %}
configuration for sonata media below.
Sonata_media.yml
sonata_media:
# if you don't use default namespace configuration
#class:
# media: MyVendor\MediaBundle\Entity\Media
# gallery: MyVendor\MediaBundle\Entity\Gallery
# gallery_has_media: MyVendor\MediaBundle\Entity\GalleryHasMedia
db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr it is mandatory to choose one here
default_context: default # you need to set a context
contexts:
default: # the default context is mandatory
download:
strategy: sonata.media.security.forbidden_strategy
providers:
#- sonata.media.provider.dailymotion
#- sonata.media.provider.youtube
- sonata.media.provider.image
- sonata.media.provider.file
#- sonata.media.provider.vimeo