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:
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)"}
[]
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.
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).
need to change the path in config.yml
sonata_media
cdn:
server:
path: /myproject/web/uploads/media
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
Related
My project is to publish images using a phone. I'm using volley library for uploading images and for the back-end side, I'm using Symfony (with file_put_contents and it works) with the liip imagine bundle in order to filter the images. I can see the images uploaded to the folder "web/uploads/img but the filtered images can't be seen in the folder "web/media/cache/{filter}. How can I do in order to get the filtered images with liip imagine?
For the Controller in Symfony:
$file = "uploads/img";
file_put_contents($file, base64_decode($image));
For the bundle liip imagine:
liip_imagine:
filter_sets:
thumb:
quality: 100
filter:
thumbnail: { size: [350, 350], mode: inset}
my_thumb:
quality: 100
filter:
thumbnail: { size: [200, 200], mode: outbound}
In your services.yaml
parameters:
image_directory: '%kernel.project_dir%/public/uploads/images'
App\Service\FileUploader:
arguments:
$targetDirectory: '%image_directory%'
config/packages/liip_imagine.yaml
liip_imagine:
filter_sets:
cache: ~
my_thumb :
quality : 75
filters :
thumbnail : { size : [260, 190], mode : outbound }
post_show:
quality: 75
filters:
thumbnail: { size: [500, 320], mode: outbound }
I have enabled pixlr as described here but is not enabled have tried many times.
There is no edit with pixlr button visible in media form.
Am I missing anything, Struggling from long time. Please help,
Is there any additional config apart from this?
Here is my config
sonata_media:
pixlr:
enabled: true
secret: theSecretHash
referrer: Demo
# if you don't use default namespace configuration
class:
media: App\Application\Sonata\MediaBundle\Entity\Media
gallery: App\Application\Sonata\MediaBundle\Entity\Gallery
gallery_has_media: App\Application\Sonata\MediaBundle\Entity\GalleryHasMedia
category: App\Application\Sonata\ClassificationBundle\Entity\Category
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 }
gallery:
providers:
- sonata.media.provider.dailymotion
- sonata.media.provider.youtube
- sonata.media.provider.image
- sonata.media.provider.file
- sonata.media.provider.vimeo
formats:
original: { width: 500, quality: 100 }
thumbnail: { width: 200, height: 200, quality: 100 }
cdn:
server:
path: http://127.0.0.1:8000/uploads/media # http://media.sonata-project.org/
filesystem:
local:
directory: "%kernel.root_dir%/../public/uploads/media" #flex
#directory: "%kernel.root_dir%/../web/uploads/media" #non-flex
create: false
After digging into the code I found the problem is with Symfony 4 making services private by default.
And this is how sonata media bundle enables pixlr
First it checks if sonata.media.extra.pixlr service is available in the container.
If not then it doesn't enable the pixlr. Since the service is private container is not able to access the service.
// Sonata\MediaBundle\Twig\GlobalVariable
/**
* #return Pixlr|bool
*/
public function getPixlr()
{
return $this->container->has('sonata.media.extra.pixlr') ? $this->container->get('sonata.media.extra.pixlr') : false;
}
Workaround for this is to override service definition and make it public :)
sonata.media.extra.pixlr:
public: true
class: Sonata\MediaBundle\Extra\Pixlr
arguments: [~,~,"#sonata.media.pool", "#sonata.media.manager.media", "#router", "#sonata.templating", "#service_container"]
Now you can see pixlr edit button enabled in media form
I managed to run the upload images via WYSIWYG CKEditor using SonataMediaBundle and CoopTilleulsCKEditorSonataMediaBundle.
The Upload works very well for ADMIN users, but does not work for users with the USER_ROLE,
Do you know how can I resolve that? thank you very much
Thank you !
config.yml
# SonataMediaBundle
sonata_media:
class:
media: Application\Sonata\MediaBundle\Entity\Media
gallery: Application\Sonata\MediaBundle\Entity\Gallery
gallery_has_media: Application\Sonata\MediaBundle\Entity\GalleryHasMedia
default_context: default
db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr
contexts:
default: # the default context is mandatory
download:
strategy: sonata.media.security.connected_strategy
mode: http
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}
news:
download:
strategy: sonata.media.security.connected_strategy
mode: http
providers:
- sonata.media.provider.youtube
- sonata.media.provider.image
formats:
small: { width: 80 , quality: 70}
big: { width: 500 , quality: 90}
cdn:
server:
path: /uploads/media # http://media.sonata-project.org/
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']
# FOSRestBundle
fos_rest:
view:
formats:
json: true
# CmfCreateBundle
cmf_create:
object_mapper_service_id: cmf_create.persistence.orm.object_mapper
# IvoryCKEditorBundle
ivory_ck_editor:
configs:
user_config:
toolbar: [ [ 'Cut','Copy','Paste','PasteText','PasteFromWord']
filebrowserUploadRoute: admin_sonata_media_media_upload
filebrowserBrowseRoute: admin_sonata_media_media_browser
filebrowserImageBrowseRoute: admin_sonata_media_media_browser
# Display images by default when clicking the image dialog browse button
filebrowserImageBrowseRouteParameters:
provider: sonata.media.provider.image
filebrowserUploadRoute: admin_sonata_media_media_upload
filebrowserUploadRouteParameters:
provider: sonata.media.provider.file
# Upload file as image when sending a file from the image dialog
filebrowserImageUploadRoute: admin_sonata_media_media_upload
filebrowserImageUploadRouteParameters:
provider: sonata.media.provider.image
context: news # Optional, to upload in a custom contexta custom context
admin_config:
toolbar: full
uiColor: "#000000"
filebrowserBrowseRoute: admin_sonata_media_media_browser
filebrowserImageBrowseRoute: admin_sonata_media_media_browser
# Display images by default when clicking the image dialog browse button
filebrowserImageBrowseRouteParameters:
provider: sonata.media.provider.image
filebrowserUploadRoute: admin_sonata_media_media_upload
filebrowserUploadRouteParameters:
provider: sonata.media.provider.file
# Upload file as image when sending a file from the image dialog
filebrowserImageUploadRoute: admin_sonata_media_media_upload
filebrowserImageUploadRouteParameters:
provider: sonata.media.provider.image
context: news # Optional, to upload in a custom contexta custom context
This error occurs when I add new image to gallery.
The filter "number_format_decimal" does not exist in
SonataMediaBundle:MediaAdmin:edit.html.twig at line 54
my config
//app/conf/config.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
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: /uploads/media # http://media.sonata-project.org/
filesystem:
local:
directory: %kernel.root_dir%/../web/uploads/media
create: false
The problem is on the sonata media bundle use "2.2.8" not "dev-master" on your composer.json and run php composer.phar update
We fixed the issue, see https://github.com/sonata-project/SonataMediaBundle/commit/352ef71a872fa3f8db1f095569bf68fe0733eafc for more information
Working well with
composer.json
"sonata-project/media-bundle": "2.2.*#dev"
I installed SonataMediaBundle and it works fine when I want to upload my files locally.
But i would like upload my files on Amazon S3. So :
i updated my config file
i added the bundle "amazonwebservices / aws-sdk-for-php" in my composer file.
But it doesn't work and i don't understand why ... is it there is any other action to do ?
Thank's a lot for your answers, i need help ... (I searched all morning before coming to ask this question)
My config.yml file :
sonata_media:
default_context: default
db_driver: doctrine_orm
contexts:
default:
providers:
- sonata.media.provider.image
formats:
small: { width: 100 , quality: 70}
big: { width: 500 , quality: 70}
Video:
providers:
- sonata.media.provider.image
- sonata.media.provider.file
formats:
small: { width: 150 , quality: 95}
big: { height: 500 , quality: 90}
cdn:
server:
path: http://mybucket.s3.amazonaws.com
filesystem:
s3:
bucket: mybucket
accessKey: myaccesskey
secretKey: mysecretkey
create: true