VichUploaderBundle
VichUploaderBundle copied to clipboard
Difference between prePersist and preUpdate event cause validation to fail.
I can't explain why this happens...
When generating a new entity with a VichFile type, validation runs after the inject function, which replaces the UploadedFile with a File object. This object cannot check the mimetype, and claims the file is missing.
When you update an existing entity with a file in the VichFile type. The validation runs before the inject and uses the UploadedFile type, which causes the mimecheck to succeed.
For me there should be no difference between an existing entity or new entity since the save/validation is based on something outside the entity.
Basically how I ensured identical behavior is by removing the inject call in the upload function, but I highly doubt that's a real solution...
I always did mime type checks on new entities without any problem
Maybe it's because it's Flysystem s3? But I see new entities injecting the File object in the validator and existing entities inject UploadedFile, which can't be right, imo they should be the same instance.
Can you provide a reference?
I'm sorry, I don't have time to make a test case.
But all I can say is the @Assert callback returns a File object for new entities that says the file is missing. And replacing an image on an existing entity works fine, when I upload a wrong file type it correctly identifies it.
The form and action are exactly the same apart from prefilling the form with an existing entity.