I can upload a file and update it. But when I update the file, I want to remove the file by myself, and that part is not working.
After playing with the bundle during hours, I can't figure out why the vich_uploader.pre_remove event is not triggered when I am doing an entity update. Only the vich_uploader.pre_upload and vich_uploader.post_upload are triggered.
But the delete_on_update option is set to true, do the vich_uploader.pre_remove should be triggered as well.
Here is my config:
App\Entity\Poll\Poll:
# File entity name
scanned_document:
# Vich mapping name in config.yml
mapping: poll_document
# Entity field name in ORM
filename_property: scanned_document_path
// *************************************************************************
// Upload file
// *************************************************************************
protected ?File $scanned_document = null;
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|UploadedFile $scannedDocument
*/
public function setScannedDocument(File $scannedDocument) : void
{
$this->scanned_document = $scannedDocument;
if ($scannedDocument) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updated = new DateTime('now');
}
}
/**
* @return File|null
*/
public function getScannedDocument() : ?File
{
return $this->scanned_document;
}
I would really appreciate some help because I am lost...
Support Question
I can upload a file and update it. But when I update the file, I want to remove the file by myself, and that part is not working.
After playing with the bundle during hours, I can't figure out why the
vich_uploader.pre_remove
event is not triggered when I am doing an entity update. Only thevich_uploader.pre_upload
andvich_uploader.post_upload
are triggered.But the delete_on_update option is set to true, do the
vich_uploader.pre_remove
should be triggered as well.Here is my config:
In the entity
I would really appreciate some help because I am lost...