0

I have problem with configure blueimp. When I send file (click: start upload) in jsconsole is:

POST XXXapp_dev.php/_uploader/gallery/upload 500 (Internal Server Error)

I used: Simple example of the entity file to be uploaded with OneupUploaderBundle https://github.com/1up-lab/OneupUploaderBundle/issues/51#issuecomment-24878715

My file: services.yml:

Cms.upload_listener:
    class: Cms\AdminBundle\EventListener\UploadListener
    arguments: [@doctrine]
    tags:
        - { name: kernel.event_listener, event: oneup_uploader.post_upload, method: onUpload }

config.yml:

oneup_uploader:
    mappings:
        gallery:
            frontend: blueimp
            storage:
                service:              ~
                type:                 filesystem
                filesystem:           ~
                directory:            web/uploads/gallery
                stream_wrapper:       ~
                sync_buffer_size:     100K

routing.yml

oneup_uploader:
    resource: .
    type: uploader

~Entity/File.php

/* ... */
    /**
     * @ORM\Entity
     * @ORM\Table(name="file")
     */
    class file {
        /**
         * @ORM\Column(type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        protected $id;

        /**
         * @ORM\Column(type="string")
         */
        protected $filename;
    }

~/EventListner/UploadListner.php

class UploadListener
{
    protected $manager;

    public function __construct(EntityManager $manager)
    {
        $this->manager = $manager;
    }

    public function onUpload(PostPersistEvent $event)
    {
        $file = $event->getFile();

        $object = new file();
        $object->setFilename($file->getPathName());

        $this->manager->persist($object);
        $this->manager->flush();
    }
}

debug route:

_uploader_upload_gallery POST ANY ANY /_uploader/gallery/upload

Directory /web/uploads/gallery is on the server.

What am I trying to achieve? I need upload files to server and add record to db.

I think that config is incorrect, but where?

Edit 1: Maybe help

INFO - An exception was thrown while getting the uncalled listeners (Catchable Fatal Error: Argument 1 passed to Cms\AdminBundle\EventListener\UploadListener::__construct() must be an instance of Cms\AdminBundle\EventListener\EntityManager, instance of Doctrine\Bundle\DoctrineBundle\Registry given, called in /home/cms/public_html/app/cache/dev/appDevDebugProjectContainer.php on line 455 and defined) Context: {"exception":"Object(Symfony\Component\Debug\Exception\ContextErrorException)"}

CRITICAL - Uncaught PHP Exception Symfony\Component\HttpFoundation\File\Exception\FileException: "Unable to create the "/uploads/gallery" directory" at /home/cms/public_html/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/File/File.php line 134 Context: {"exception":"Object(Symfony\Component\HttpFoundation\File\Exception\FileException)"}

I created uploads/gallery! chmod 777. I don't understand.

Edit 2:

Cms.upload_listener:
    class: Cms\AdminBundle\EventListener\UploadListener
    arguments: ["@doctrine.orm.entity_manager"]
    tags:
        - { name: kernel.event_listener, event: oneup_uploader.post_upload, method: onUpload }

and:

directory:            ./uploads/gallery

Now created, uploaded file in "uploads/gallery/..." But...

CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Catchable Fatal Error: Argument 1 passed to Cms\AdminBundle\EventListener\UploadListener::onUpload() must be an instance of Oneup\UploaderBundle\Event\PostPersistEvent, instance of Oneup\UploaderBundle\Event\PostUploadEvent given" at /home/cms/public_html/src/Cms/AdminBundle/EventListener/UploadListener.php line 17 Context: {"exception":"Object(Symfony\Component\Debug\Exception\ContextErrorException)"}

Returns blueimp "Internal Server Error ..." and doesn't add records in the Entity.

Community
  • 1
  • 1
viko
  • 491
  • 6
  • 23

0 Answers0