Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonataMediaBundle: Files/Images not found

I'm using SonataMediaBundle with SonataAdminBundle and Symfony 2.3.

When I try to upload an image via the Sonata Admin interface:

  1. Click on "Add New" (app_dev.php/admin/sonata/media/media/create)
  2. Click on "Image" (app_dev.php/admin/sonata/media/media/create?provider=sonata.media.provider.image&context=default)
  3. Browse the image.jpg file and click on "create"
  4. This leads me to the edit page where I can see: Item "image.jpg" has been successfully created.

And indeed:

  • In the folder web\uploads\media\default\0001\01 I have my image file and the 3 thumbs
  • In the media__media DB table I have the corresponding line
  • When I browse web/uploads/media/default/0001/01/ with Firefox I can see my image
  • The corresponding line appears in the media list (in admin panel)

But:

  • The image is not displayed in the media list (there is a square instead of the thumb) nor in the image edit page (app_dev.php/admin/sonata/media/media/3/edit?provider=sonata.media.provider.image&context=default)

For the files, it's even worse:

  1. Click on "Add New" (app_dev.php/admin/sonata/media/media/create)
  2. Click on "Image" (app_dev.php/admin/sonata/media/media/create?provider=sonata.media.provider.file&context=default)
  3. Browse the document.zip file and click on "create"

This generates the error 500: The file "" does not exist. And no new line is created in the DB.


Piece of solution

For the image problem, I noticed that the path where sonata admin was looking was not the good one: I it looking in: http://myserver/uploads/media/default/0001/01/c35f187f1b405f4bfba8b962d83e5bbdccff54f9.jpeg

Instead of http://myserver/myproject/web/uploads/media/default/0001/01/c35f187f1b405f4bfba8b962d83e5bbdccff54f9.jpeg

Apparently, this is due to this part of the config.yml (as defined in SonataMedia documentation):

sonata_media
    cdn:
        server:
            path: /uploads/media

That I replaced by:

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

And it works. But I don't think it's a good idea to hardcode this there. And I guess that there is a good reason why it it written this way in the Sonata Doc, no?

Is my modification correct? If not, how should I do?

In any case, it doesn't solve my file uploading problem! Any idea on this point?

like image 661
Blacksad Avatar asked Feb 27 '14 10:02

Blacksad


1 Answers

The file "" does not exist

As explained here, this is caused by insufficient limit for allowed upload file size in php.ini (increase upload_max_filesize and post_max_size).

Then you will probably stumble on another error saying that the zip file type is not allowed, so add this into your config.yml:

sonata_media:   
    providers:
        file:
            allowed_extensions: ['zip']
like image 67
Jan Šimek Avatar answered Sep 25 '22 18:09

Jan Šimek