1
votes

I have a problem with the Sonata Media bundle. Images that i upload on server (local) are not displayed (thumbnail missing). I checked the path and it's all correct. All images that I uploaded is transferred to the directory /web/ uploads/media .

Check Screenshot:

enter image description here

Full size screenshot here

Config File:

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:
                preview:   { width: 100, quality: 100}
                small: { width: 100 , quality: 70}
                big:   { width: 500 , quality: 70}

    cdn:
        server:
            path: uploads/media

    filesystem:
        local:
            directory:  %kernel.root_dir%/../web/uploads/media
            create:     false

sonata_notification:
    backend: sonata.notification.backend.runtime

sonata_notification:
    admin:
        enabled: false

Am using Media bundle in Sonata admin bundle like this and all work good but just that thumbnail is not rendered. I read Media BUndle doc Helper section but dont understand.

In my ArticleAdmin controlir i adding filend like this:

/**
 * Configure Form Fields
 *
 * Fields to be shown on create/edit forms
 */
protected function configureFormFields(FormMapper $formMapper)
{
    $link_parameters = array();

    if ($this->hasParentFieldDescription()) {
        $link_parameters = $this->getParentFieldDescription()->getOption('link_parameters', array());
    }

    if ($this->hasRequest()) {
        $context = $this->getRequest()->get('context', null);

        if (null !== $context) {
            $link_parameters['context'] = $context;
        }
    }
$formMapper->add('media', 'sonata_type_model_list', array('required' => false), array(
                'link_parameters' => $link_parameters
           ))
}

Any solution?


UPDATE:

In my log file, I found this :

[2015-01-22 15:28:22] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /admin/sonata/media/media/uploads/media/default/0001/01/thumb_1_admin.jpeg"" at C:\xampp\htdocs\Symfony\app\cache\dev\classes.php line 2017 {"exception":"[object] (Symfony\Component\HttpKernel\Exception\NotFoundHttpException(code: 0): No route found for \"GET /admin/sonata/media/media/uploads/media/default/0001/01/thumb_1_admin.jpeg\" at C:\xampp\htdocs\Symfony\app\cache\dev\classes.php:2017, Symfony\Component\Routing\Exception\ResourceNotFoundException(code: 0): at C:\xampp\htdocs\Symfony\app\cache\dev\appDevUrlMatcher.php:521)"} []

4
Copy image path and open that url in new tab see the error either its generating a 404 error or another also check logs too for that requestM Khalid Junaid
http://localhost/Symfony/web/uploads/media/default/0001/01/thumb_1_admin.jpeg everything is good. the image is displayed without any errorsIvan
Check update in question for logIvan
You have a double media folder in the PHP Exception: "../sonata/media/media/uploads/.."11mb

4 Answers

0
votes

Your link should be something like '/uploads/media/....' and not 'upload/media/...'

In your config file, change

cdn: server: path: uploads/media

to

cdn: server: path: /uploads/media

Hope it helps to solve your problem.

0
votes

In addition to Stiff Roy answer, you can set your virtual host root to Symfony/web (in your case).

So when you will be on http://localhost/app_dev.php/admin/sonata/media/media/list your images load as http://localhost/uploads/media/default/0001/01/thumb.jpg

Error "No route found for "GET /admin/sonata/media/media/uploads/media/default/0001/01/thumb_1_admin.jpeg"" says that it tried to load an image through controller and not by the direct access. Additional info about setting your env could be found here or here (PHP Storm).

0
votes

need to change the path in config.yml

sonata_media
    cdn:
        server:
            path: /myproject/web/uploads/media
0
votes

ok so I solved the problem this way:

  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
        providers:
            - sonata.media.provider.dailymotion
            - sonata.media.provider.youtube
            - sonata.media.provider.image
            - sonata.media.provider.file
            - sonata.media.provider.vimeo

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

cdn:
    server:
        path: "/uploads/media" # http://media.sonata-project.org/

filesystem:
    local:
        directory:  "%kernel.root_dir%/../web/uploads/media"
        create:     false

and in the console : $php app/console server:start

The symphony environment app_dev is not working with the sonata media bundle.

Cheers