简体   繁体   中英

Sonata media bundle - pdf upload shows ROLE Error

I have a working image uploader with the mediabundle, but it looks like the fileupload doesn't work.

i tried to upload a pdf file , and got the following error:

The media can be retrieved by users with the following roles : ROLE_SUPER_ADMIN, ROLE_ADMIN. 

I am 100% sure that I have the right admin roles. After a deep search in the code I found, that the /sonata-project/doctrine-phpcr-admin-bundle/Model/ModelManager.php create function drops an error:

String(83) "Field "width" of class "Application\Sonata\MediaBundle\PHPCR\Media" is not nullable"

I think my config.yml should be fine :

 providers:
    file:
        service:    sonata.media.provider.file
        resizer:    false
        filesystem: sonata.media.filesystem.local
        thumbnail:  sonata.media.thumbnail.format
        allowed_extensions: ['pdf', 'txt', 'rtf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pttx', 'odt', 'odg', 'odp', 'ods', 'odc', 'odf', 'odb', 'csv', 'xml']
        allowed_mime_types: ['application/pdf', 'application/x-pdf', 'application/rtf', 'text/html', 'text/rtf', 'text/plain']


    image:
        filesystem: sonata.media.filesystem.s3
        allowed_extensions: ['jpg', 'png', 'jpeg', 'gif']
        allowed_mime_types: ['image/pjpeg', 'image/jpeg', 'image/png', 'image/x-png', 'image/gif']
        resizer: sonata.media.resizer.custom

when I tried to add locally as you can see the config above it still didn't work. Neuther on the sonata.media.filesystem.s3 Could the missing default pdf template image should cause the issue? Or has someone a similar issue before?

The resizer expected width and height. Even if the resizer is not necessary for pdf, it should have been in Application\\Sonata\\MediaBundle\\PHPCR\\Media class:

<?php
namespace Application\Sonata\MediaBundle\PHPCR;
use Sonata\MediaBundle\PHPCR\BaseMedia as BaseMedia;
/**
 * Media class
 *
 * @see https://sonata-project.org/bundles/easy-extends
 * @see http://docs.doctrine-project.org/projects/doctrine-phpcr-odm/en/latest/index.html
 */
class Media extends BaseMedia
{
    /**
     * @var integer
     */
    protected $id;
    /**
     * @var integer
     */
    protected $width = 0;
    /**
     * @var integer
     */
    protected $height = 0;
    /**
     * Get ID
     *
     * @return integer $id
     */
    public function getId()
    {
        return $this->id;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM