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

Handling image upload when one already exists #115

Open
seydu opened this issue Sep 23, 2014 · 3 comments
Open

Handling image upload when one already exists #115

seydu opened this issue Sep 23, 2014 · 3 comments
Milestone

Comments

@seydu
Copy link

seydu commented Sep 23, 2014

When I submit a form without uploading an image I lose the image I had previously uploaded.
I don't see anything in the doc to handle this situation.

Is something planed to handle this ?
I used to handle this with Javascript and some tweak server side:
The server sets some information in the response to let the JS know if an image already exists. If yes it hides the upload field, removes the "required" if any and adds a button to show the upload when clicked.

@dbu
Copy link
Member

dbu commented Sep 25, 2014

this seems a dilemma of http and the form layer: when submitting the form, the browser obviously does not re-send the file. the form layer does not magically insert the file when it was not changed - that could be very expensive and confusing as you don't know if the user uploaded a new file or you still have the same file. so you do need to detect this situation specifically - not sure why the form layer does not detect the file was not changed. if it would do that and not call the setter method, things would be simpler. this is what we use in the BlockBundle: https://github.com/symfony-cmf/BlockBundle/blob/master/Doctrine/Phpcr/ImagineBlock.php#L132-L176

do we have a document in the MediaBundle that would need the same logic?

@seydu
Copy link
Author

seydu commented Sep 25, 2014

Yes.
I have seen this problem in many applications (base on known framworks or in house ones).
Though the solution I described in my firt post is being used in many apps in an in house framework, I don't like it. And in the context of Symfony I don't want to allow myself to use it because there should be a cleaner way to do it.

I have a document that extends Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\Image and adds an image (\Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\Image).

Since I am SonataAdmin, I can use its functionality that allows to remove some fields before binding (I don't remember where I have seen it in the doc, I will have to check). Hoping a won't have a problem with the CRFS protection in the form layer.

@dbu
Copy link
Member

dbu commented Sep 26, 2014

i think we already have an issue talking about this: #8 - if you have a generic solution that you think we could provide with sonata / media bundle i would love to see PRs .

from a user point of view, i see two cases:

  1. Image required: On new document, i must upload an image. Later on i may upload an image to replace the existing image.
  2. Image optional: On a new or existing document i may upload an image to create/replace it. If there already is an image, i additionally have a little "delete" button to remove the currently uploaded image from the document on save.

I don't know what the most elegant and generic solution on server side is for this, how far the form layer can help with not overwriting an image when none was uploaded.

@lsmith77 lsmith77 added this to the 1.3 milestone Jun 17, 2015
@dbu dbu removed this from the 1.3 milestone Feb 1, 2016
@ElectricMaxxx ElectricMaxxx added this to the 2.0 milestone Jan 5, 2017
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

No branches or pull requests

4 participants