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
Related
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 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
I am using LiipImageBundle & KNP Gaufrette bundle to resize & load images from s3. It was all working before but suddenly it stopped working. There are no bundle version upgrades.
Below is my configuration,
liip_imagine:
cache: aws_s3_images
data_loader: stream.aws_s3_images
filter_sets:
large:
quality: 75
cache: aws_s3_images
data_loader: stream.aws_s3_images
filters:
relative_resize: { widen: 140 }
medium:
quality: 75
cache: aws_s3_images
data_loader: stream.aws_s3_images
filters:
thumbnail: { size: [50, 50], mode: outbound }
small:
quality: 75
cache: aws_s3_images
data_loader: stream.aws_s3_images
filters:
thumbnail: { size: [25, 25], mode: outbound }
loaders:
stream.aws_s3_images:
stream:
wrapper: gaufrette://aws_s3_images_fs/
knp_gaufrette:
adapters:
aws_s3_images_adapter:
aws_s3:
service_id: 'st.aws_s3.client'
bucket_name: %amazon.s3.bucket%
options:
#directory: 'fos'
create: true
filesystems:
aws_s3_images_fs:
adapter: aws_s3_images_adapter
stream_wrapper: ~
The problem is strange, if I open image in new tab, it redirects to s3 image url and displays image. Once it loads in new tab, then it starts displaying normally. It doesnt work unless I open it new new tab.
is it not resolving s3 path ? What could be the issue ? I tried deleting all cache, I don't have media folder in my web directory.
In log it shows ImagineController:FilterAction is called.
In html source image path is
http://st.com/app_dev.php/media/cache/resolve/large/fos/user/ebc36103e6d1038791eb7eca2f4449db0780fdf41416235134.jpeg
Now if I open it in new tab/window, it will redirect to
[MY_S3_BUCKET_URL]/fos/user/large/ebc36103e6d1038791eb7eca2f4449db0780fdf41416235134.jpeg
and will display image in new window.
Now if I again refresh my page, image source is now changed to
[MY_S3_BUCKET_URL]/fos/user/large/ebc36103e6d1038791eb7eca2f4449db0780fdf41416235134.jpeg
and now I can see image loaded ?
Why it started happening suddenly. It was all working properly before.
After going through all the code of LiipImaginBundle & debugging, it turned out to be content type issue which was caused by FOSRestBundle's
format_listener:
rules:
- { path: '^/', priorities: [ '*/*' ], fallback_format: html, prefer_extension: true }
Changing it to
format_listener:
rules:
- { path: '^/', priorities: [ 'html', '*/*' ], fallback_format: html, prefer_extension: true }
fixed the issue.
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