Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

The file upload is not picked up, if the file is the only field that has changed #123

Closed
WishCow opened this issue Mar 5, 2013 · 13 comments

Comments

@WishCow
Copy link

WishCow commented Mar 5, 2013

If you have a user model, that has 4 attributes:

  • id
  • name
  • picture
  • picturePath

Id, name, and picturePath are persisted through Doctrine, the picture attribute is the one with the @Vich/UploadableField annotation, and has "picturePath" as its fileNameProperty attribute.

Create a form for this entity, then upload a new file, and modify nothing else on the form. The change will not be picked up. This is because the UploaderListener is listening on the prePersist and preUpdate events, which are never fired, since the only field that is modified by the form is the "picture" field, which is not mapped by Doctrine.

@sheeep
Copy link

sheeep commented Mar 6, 2013

This is because the UploaderListener is listening on the prePersist and preUpdate events, which are never fired, since the only field that is modified by the form is the "picture" field, which is not mapped by Doctrine.

I had the exact same problem today and solved it with a pretty nasty workaround. I have a field updated which is mapped by Doctrine (and handled by Gedmo\Timestampable) so I just update this field every time I update the base entity.

$image->setUpdated(new \DateTime());

This way it will always update your image field. Indeed this is not the solution I was looking for, but a pretty painless one after all.

@WishCow
Copy link
Author

WishCow commented Mar 7, 2013

I ended up with something similar, I modified the setPictureFile() method on my entity:

public function setPictureFile($pictureFile) {
    $this->pictureFile = $pictureFile;
    if ($pictureFile) {
        $this->picture = $pictureFile->getFileName();
    }
}

The pictureFile attribute is the one with the uploader annotation. This seems somewhat safe, since it will be overwritten at flush time by the uploader.

@Baachi
Copy link
Contributor

Baachi commented Mar 7, 2013

@WishCow @sheeep this is related to the issue #8 and PR #106.

@gido
Copy link
Contributor

gido commented Nov 18, 2013

lost some time today to understand why the file upload don't work anymore. We should add something about this "issue" in the doc.

@ftassi
Copy link
Collaborator

ftassi commented Nov 18, 2013

Duplicated by #8

@ftassi ftassi closed this as completed Nov 18, 2013
ftassi pushed a commit that referenced this issue Nov 18, 2013
ftassi added a commit that referenced this issue Nov 18, 2013
@hediyedel
Copy link

Hi everyone. I'm new at symfony.
I installed VichUploaderBundle ,but I didn't understand how to use it in my project.
I wonder if you could help me please?

@ftassi
Copy link
Collaborator

ftassi commented Nov 19, 2013

@hediyedel You should read the doc and then come back with a more specific question. If something is not clear in the doc let us know.

@hediyedel
Copy link

@ftassi I've read it and done all changes, but when I copy {{ product.name }} in my twig or
$entity = // get the entity..
$helper = $this->container->get('vich_uploader.templating.helper.uploader_helper');
$path = $helper->asset($entity, 'image');
in my controller,I have this error: " The object is not uploadable. 500 Internal Server Error - InvalidArgumentException "
How can I solve it?

@ftassi
Copy link
Collaborator

ftassi commented Nov 19, 2013

Double check you annotation on the Entity class and open a dedicated issue for your problem, this one is not related to it.

@AlmogBaku
Copy link

is there no any solution yet?

@DavidM974
Copy link

Hi, i'm testing your bundle and when i save my Image entity the file is lost. My conf is like the exemple. Is it possible that my event listener is not call? even if my updatedAt is update in my database?

@K-Phoen
Copy link
Collaborator

K-Phoen commented Feb 1, 2016

@DavidM974 Can you open a new issue for your problem? Giving us your configuration would be nice too :)

@DavidM974
Copy link

Thanks for your quick answer my bad!
i forgot the annotation on the class ...
* @Vich\Uploadable */ class Image {

Now it works!

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

Successfully merging a pull request may close this issue.

9 participants