2

I created a context that would contain only zip files. I need to be able to only allow zip file extension on this context. I was able to create a custom provider that extends to FileProvider but having a problem setting the specific extension allowed on this provider.

I followed this post: sonata-media-bundle-how-to-write-custom-provider

When I set the configuration to the following:

providers:
    custom:
        allowed_extensions: ['zip']
        allowed_mime_types: ['application/zip','application/x-zip']

Symfony throws an error:

Fatal error: Uncaught exception 'Symfony\Component\Config\Definition\Exception\InvalidConfigurationException' with message 'Unrecognized options "custom" under "sonata_media.providers"'
Community
  • 1
  • 1
Awesemo
  • 23
  • 5
  • I have created SVG provider once and in config i have limit extension you can have a look at this answer for better idea http://stackoverflow.com/a/32847495/853360 – M Khalid Junaid Jul 29 '16 at 09:56

1 Answers1

1

Manage to find it after going through the media bundle code.

Allowed extensions and mime types are 6 and 7 arguments for a provider. Following is copy of my service.yml file for declaring a custom provider service.

services:
sonata.media.provider.custom:
    class: Application\Sonata\MediaBundle\Provider\CustomProvider
    tags:
        - { name: sonata.media.provider }
    arguments:
        - sonata.media.provider.custom
        - @sonata.media.filesystem.local
        - @sonata.media.cdn.server
        - @sonata.media.generator.default
        - @sonata.media.thumbnail.format
        - ['zip', 'foo']
        - ['application/zip', 'foo/bar']
GSB
  • 21
  • 2