Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

onUpload UploadListener notwork!! #40

Closed
nephilimdie opened this issue Aug 9, 2013 · 9 comments
Closed

onUpload UploadListener notwork!! #40

nephilimdie opened this issue Aug 9, 2013 · 9 comments
Labels

Comments

@nephilimdie
Copy link

hi, i've problem when i try to use listener. Maybe is my fault. I'm in symfony 2.3 with postgresSQL. I try to use that with sonata media.

        $request = $event->getRequest();
        $file = $this->getFiles($request->files);
        die(var_dump($file));
        $gallery = $request->get('gallery');
        $file = $request->files->get('upload');
...etc

my service

services:
  ## post pre update event after persist object
  media.upload_listener:
      class: 'Kdig\MediaBundle\EventListener\UploadListener'
      arguments: [ '@service_container' ]
      tags:
          - { name: container.event_listener, event: oneup_uploader.post_persist, method: onUpload }

"die()" not work.
Can you explain me why?

thanks in advance
regards
Stefano

@sheeep
Copy link
Contributor

sheeep commented Aug 9, 2013

Hi Stefano

I guess this is the EventListener you are talking about. Am I right?

Why do you call a getFiles method on the $this object, where there is no such method available? You can get the file from the event object like this:

$file = $event->getFile();

Could you verify if the constructor of the Listener gets called?

@nephilimdie
Copy link
Author

thank you for your quickly answer.
yep, is right, is my project, for my university. trying to create archaeological data system.

is one of chance that i choose trying to understand the problem.
i cheanged with var_dump($request); but the issue is the same.

I use this for my template from blueimp page
index.html.twig

it is as if the listener is not called.

@sheeep
Copy link
Contributor

sheeep commented Aug 9, 2013

There are several possibilities why the Listener does not get called.

  • The listener somehow doesn't get registered. You can verify that by calling $> php app/console container:debug and see if the media.upload_listener appears in this list.
  • There is no file in the request. Try to add a var_dump(count($files)); after Line 18 in the BlueimpController in your vendor folder. It should return a number > 0.
  • If the Controller in the previous point does not get called, check the Ajax-Request from the Client to the Server: Is the url correct? Is at least one file attached? What is the response?

But you should probably first check this one: In the docs the name of the tag is kernel.event_listener and not container.event_listener like in your example.

<tag name="kernel.event_listener" event="oneup_uploader.post_persist" method="onUpload" />

Try change the tag-name to kernel.event_listener.

@nephilimdie
Copy link
Author

i am sorry. When i changed container to kernel is started to work well. Now i see the response.
Thank you for everything and for your time! :)

stefano

@aratinau
Copy link

Hello !
Can we see what there is in your onUpload method please !

@sheeep
Copy link
Contributor

sheeep commented Sep 20, 2013

@aymerixp Please specify your problem. I'm happy to help.

If you think it could be a problem with the bundle itself, ask here or in a new ticket. If you think it's more question-like, consider posting your problem to Stackoverflow, so others can profit from it too. (Remember tagging your question with Symfony2 and upload or file-upload).

@aratinau
Copy link

I asking here because my fronted return me "Error Empty file upload result".
So i understand there is no response returned so i would like to know what return !

@sheeep
Copy link
Contributor

sheeep commented Sep 20, 2013

so i would like to know what return !

There was already an issue and a Stackoverflow thread regarding return values for jQuery File Uploader. Furthermore, take a look at the official documentation and the Return custom data to the Frontend section of this bundle. You should end up with something like this.

namespace Acme\HelloBundle\EventListener;

use Oneup\UploaderBundle\Event\PostPersistEvent;

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

        $response['files'] = array(
            array(
                'name' => $file->getFilename(),
                'url' => //...
                'thumbnail_url' => //...
                // more keys ..
            )
        );
    }
}

There reason why this bundle does not return anything by default is the fact, that you could implement a custom JavaScript function to handle return values. You're not bound to this scheme.

@aratinau
Copy link

That exactly what I was looking for ! Thank you a lot ! It works great !

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants