-
Notifications
You must be signed in to change notification settings - Fork 40
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
Comments
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? |
Yes. 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. |
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:
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. |
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.
The text was updated successfully, but these errors were encountered: