We have a case where we want to use all of vich's behind the scenes magic with files that are already in the filesystem (for image import for example) eg:
...
$asset = New Asset();
$asset->setAssetFile(new UploadedFile($filepath, $image->getFilename()));
$this->entityManager->persist($asset);
$this->entityManager->flush();
But it doesn't work as /vich/uploader-bundle/Handler/UploadHandler.php line 120 requires a UploadedFile, and then when moving the file, UploadedFile method isValid fails because we simulated an UploadedFile, it wasn't a real uploaded file.
Would it be good to have a flag to allow instances of File too? I can work on a PR for it.
I think it could be simpler in your case to extend UploadHandler and to override vich_uploader.upload_handler service definition.
I don't think it could make sense to support non-uploaded files in a bundle named "Uploader"
Ok, will do that, thanks.
Thing is, it worked fine with gauffrette, but when we switched to Symfony's filesystem we got this issue, so in fact your bundle also works with non uploaded files in some cases.
I would also need to override AbstractStorage as it checks for UploadedFile there too..
Emulate UploadedFile using sixth parameter (test=true):
$pathToTmpImageFile= copy('...', '...');
$imageObject = new UploadedFile($pathToTmpImageFile, $imageName, $mimeType, filesize($pathToTmpImageFile), null, true);
$entity->setUploadedFile($imageObject);
$em->persist($entity);
$em->flush();
Yes, that was another option but it felt wrong using a test flag in production...thanks!
It's ok for emulating file uploading.
@gonzalovilaseca feel free open PR with adding some howto section in docs https://github.com/dustin10/VichUploaderBundle/tree/master/Resources/doc which would help people solve issues like your.
Most helpful comment
Emulate
UploadedFileusing sixth parameter (test=true):