Search code examples
phpjquerysymfonyoneupuploaderbundle

OneupUploaderBundle: Files are not uploaded, why?


I'm trying to upload files using OneupUploaderBundle and pretty much all is working but files aren't uploaded and I can't find where the issue is. This is how my UploadLister looks:

namespace AppBundle\EventListener;

use Oneup\UploaderBundle\Event\PostUploadEvent;
use Oneup\UploaderBundle\Event\PreUploadEvent;
use AppBundle\Entity;

class UploadListener
{
    protected $doctrine;
    protected $originalName;
    protected $tipoRecaudo3;
    protected $tipoRecaudo4;
    protected $tipoRecaudo5;

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

    public function onUpload(PreUploadEvent $event)
    {
        $file = $event->getFile();
        $response = $event->getResponse();

        $this->originalName = $file->getClientOriginalName();
        $this->tipoRecaudo3 = $event->getRequest()->get('tipoRecaudo3', null);
        $this->tipoRecaudo4 = $event->getRequest()->get('tipoRecaudo4', null);
        $this->tipoRecaudo5 = $event->getRequest()->get('tipoRecaudo5', null);

        $url = "";
        $deleteUrl = "";

        $response['files'] = [
            'name' => $file->getClientOriginalName(),
            'size' => $file->getSize(),
            'url' => $url,
            'deleteUrl' => $deleteUrl,
            'deleteType' => 'DELETE'
        ];
    }

    public function onPostUpload(PostUploadEvent $event)
    {
        $em = $this->doctrine->getManager();
        $request = $event->getRequest();

        $productoSolicitud = $em->getRepository('AppBundle:ProductoSolicitud')->find($request->getSession()->get('productoSolicitudId'));

        $recaudosTramiteProductoSolicitud = new Entity\RecaudosTramitesProductoSolicitud();
        $recaudosTramiteProductoSolicitud->setProductoSolicitud($productoSolicitud);
        $recaudosTramiteProductoSolicitud->setArchivo($this->originalName);

        if ($this->tipoRecaudo3 !== null)
        {
            $recaudosTramiteId = $this->tipoRecaudo3;
        } else if ($this->tipoRecaudo4 !== null)
        {
            $recaudosTramiteId = $this->tipoRecaudo4;
        } elseif ($this->tipoRecaudo5 !== null)
        {
            $recaudosTramiteId = $this->tipoRecaudo5;
        }

        $recadudoTramite = $em->getRepository('AppBundle:RecaudosTramite')->find($recaudosTramiteId);
        $recaudosTramiteProductoSolicitud->setRecaudosTramite($recadudoTramite);

        $em->persist($recaudosTramiteProductoSolicitud);
        $em->flush();
    }
}

And it works since entities are persisted to BD. Now this is how my configuration for the bundle looks at config.yml:

oneup_uploader:
    mappings:
        recaudos:
            frontend: blueimp
            storage:
                service:              ~
                type:                 filesystem
                filesystem:           ~
                directory:            %kernel.root_dir%/../web/uploads/recaudos
                stream_wrapper:       ~
            allowed_mimetypes:     [application/msword,image/jpeg,image/pjpeg,image/png,application/pdf,application/vnd.oasis.opendocument.text]
            error_handler:        oneup_uploader.error_handler.noop

            use_orphanage:        true
            enable_progress:      true
            enable_cancelation:   true
            namer:                oneup_uploader.namer.uniqid

And at Twig template level this is what I've:

<form id="cargaRecaudos3" action="" method="POST" enctype="multipart/form-data" class="form-horizontal" role="form">
<input id="fileUpload3" class="fileUpload" type="file" name="fileUpload3[]" data-url="{{ oneup_uploader_endpoint('recaudos') }}" multiple />
</form>

And of course the component is initialized at jQuery level:

$(document).ready(function(){
    $('#fileUpload3').fileupload();
});

Any ideas why the files aren't uploaded? I'm using the same folder from within VichUploader bundle and those files are uploaded so permissions might be not the problem, any ideas?

Edit

I write a die('meep') as says here and the response returns the die but file still not upload, any advice on this?


Solution

  • First

    If it is you first run of this bundle, there is a frequent error that all people do: check if your folder web can be written...

    Second

    Try to make you config of the bundle simple like this:

    oneup_uploader:
        mappings:
            recaudos:
                frontend: blueimp 
                enable_progress: true