symfonysonata-adminsonata-media-bundle

png file can't be uploaded sonata-media-bundle


I have set upped sonatamediabundle

I can upload jpg file correctly though,when I try to upload the png file.

it shows error.

An error has occurred during the creation of item "n/a".

my config.yml is like this. I think I set the png file config correctly. Is there any other check point for uploading png??

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
    default_context: default
    db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr
    contexts:
        default:  # the default context is mandatory
            providers:
                - sonata.media.provider.dailymotion
                - sonata.media.provider.youtube
                - sonata.media.provider.image
                - sonata.media.provider.file

            formats:
                small: { width: 100 , quality: 70}
                big:   { width: 500 , quality: 70}

    cdn:
        server:
            path: /myapp/web/uploads/media # Its not good I need to change depending on server...

    filesystem:
        local:
            directory:  %kernel.root_dir%/../web/uploads/media
            create:     false
    providers:
        image:
            service:    sonata.media.provider.image
            resizer:    sonata.media.resizer.simple # sonata.media.resizer.square
            filesystem: sonata.media.filesystem.local
            cdn:        sonata.media.cdn.server
            generator:  sonata.media.generator.default
            thumbnail:  sonata.media.thumbnail.format
            allowed_extensions: ['jpg', 'png', 'jpeg']
            allowed_mime_types: ['image/pjpeg', 'image/jpeg', 'image/png', 'image/x-png']

Solution

  • You have to check your form: configureFormFields()

    The error is catch up there:

    // show an error message if the form failed validation
            if (!$isFormValid) {
                if (!$this->isXmlHttpRequest()) {
                    $this->addFlash('sonata_flash_error', $this->admin->trans('flash_create_error', array('%name%' => $this->admin->toString($object)), 'SonataAdminBundle'));
                }
            }