Closed indapublic closed 6 years ago
Try to force directories
in your config
@garak can you show example? current documentation (https://github.com/dustin10/VichUploaderBundle/blob/master/Resources/doc/mapping/yaml.md) seems outdated for symfony 4.
While examples are more old-Symfony oriented, you can use them with Symfony 4 as well. Just adapt your paths
An exception has been thrown during the rendering of a template ("The class "App\Entity\File" is not uploadable. If you use annotations to configure VichUploaderBundle, you probably just forgot to add
@Vich\Uploadable
on top of your entity. If you don't use annotations, check that the configuration files are in the right place. In both cases, clearing the cache can also solve the issue.").
src/Resource/config/vich_uploader/Entity.File.yml:
App\Entity\File:
file:
mapping: file
filename_property: fileName
Be aware that "clearing the cache" means manually deleting all your cache files/dirs.
Then, you can try to check if your entities are uploadable using console commands provided by this bundle.
Did you force directories
option?
see Vich\UploaderBundle\DependencyInjection\VichUploaderExtension::registerMetadataDirectories
and Metadata\Driver\FileLocator::findFileForClass
(part of https://github.com/schmittjoh/metadata).
working config:
config/vich_uploader/Entity.File.yml
App\Entity\File:
file:
mapping: file
filename_property: fileName
config/packages/vich_uploader.yaml
vich_uploader:
db_driver: orm
mappings:
file:
namer: Vich\UploaderBundle\Naming\UniqidNamer
# ... my config
metadata:
auto_detection: false
directories:
- {path: '%kernel.project_dir%/config/vich_uploader', namespace_prefix: 'App'}
But to be honest, with this inadequately complicated configuration you need to do something. Because the bundle is unreasonably difficult to configure.
Feel free to propose a more reasonable solution, if you can find one.
Try to force directories - no success
Please provide the content of your mapping file. And remember:
you can try to check if your entities are uploadable using console commands provided by this bundle
As I said before, i create mapping file with invalid YML (just for checking) and I cannot see any errors, so I think that file hasn't been imported.
vich_uploader.yml
(from config
)
vich_uploader:
db_driver: orm
# templating: true
# twig: true
# form: true
# storage: file_system
mappings:
tuning_part_image:
uri_prefix: '%app.path.tuning_part_images%'
upload_destination: '%kernel.root_dir%/../web/uploads/images/tuning_parts'
inject_on_load: false
delete_on_update: true
delete_on_remove: true
metadata:
auto_detection: false
directories:
- { path: '%kernel.root_dir%/vich_uploader', namespace_prefix: 'Admin' }
Hm.... I not see any vich
commands in bin/console
. Just checked in AppKernel
, bundle has been included. Any thoughts?
+ @indapublic I don't see any console commands either
@Gemorroj What are your versions of Symfony and Vich?
@indapublic Symfony 4.0.8, Vich 1.8.2
Are you using flex? Anyway, Symfony4 should use config/bundles.php
instead of AppKernel
@garak yes, flex. config/bundles.php
have Vich\UploaderBundle\VichUploaderBundle::class => ['all' => true],
but, php bin/console list
does not display vich commands
@garak I'm not.
You can try with latest dev-master (or 1.8.*@dev
), commands should appear now.
Commands are appeared, thank you @garak
bin/console vich:mapping:list-classes
In FileLocator.php line 51:
RecursiveDirectoryIterator::__construct(/Volumes/Data/www/website/admin/app/vich_uploader): failed to open dir: No such file or directory
I'm not sure why it looking for app/vich_uploader
@garak now with console commands everything is fine
@indapublic you configured path: '%kernel.root_dir%/vich_uploader'
, so it's your fault.
@garak Agreed, lost control with tests. Sorry. Yes, my class is attached.
bin/console vich:mapping:list-classes Looking for uploadable classes. Found Admin\TuningPart\TuningPartImage Found 1 classes. NOTE: Only classes configured using XML or YAML are displayed.
So. Bundle can see my YML in vich_uploader
. YML contains invalid data
But no errors at the moment
Your YAML is not strictly invalid, but I see it does not contains useful mapping informations. Why didn't you try with a useful one?
Trying with this...
AdminBundle\TuningPart\TuningPartImage:
imageFile:
mapping: tuning_part_image
filename_property: imageFileName
bin/console vich:mapping:list-classes Looking for uploadable classes. Found Admin\TuningPart\TuningPartImage Found 1 classes. NOTE: Only classes configured using XML or YAML are displayed.
bin/console vich:mapping:debug tuning_part_image Debug information for mapping tuning_part_image uri_prefix: '/uploads/images/tuning_parts' upload_destination: '/Volumes/Data/www/ru.compositdv/admin/app/../web/uploads/images/tuning_parts' inject_on_load: false delete_on_update: true delete_on_remove: true namer: array ( 'service' => NULL, 'options' => NULL, ) directory_namer: array ( 'service' => NULL, 'options' => NULL, ) db_driver: 'orm'
Easy admin configuration:
...
- { property: 'imageFile', type: 'vich_file', base_path: '%app.path.tuning_part_images%' }
...
Still receiving Mapping not found for field "imageFile"
bin/console vich:mapping:debug-class "Admin\TuningPart\TuningPartImage"
Thanks, I'm found that I'm using wrong namespace in vich_uploader.yml
. Fixed.
- { path: '%kernel.root_dir%/config/vich_uploader', namespace_prefix: 'AdminBundle' }
Running your command (with correct bundle namespace):
bin/console vich:mapping:debug-class "AdminBundle\TuningPart\TuningPartImage" Introspecting class AdminBundle\TuningPart\TuningPartImage:
But still not working in Easy Admin :(
Rework project in annotation instead of yml and all works fine. If I removed annotation from property
@Vich\UploadableField(mapping="tuning_part_image", fileNameProperty="imageFileName")
I receive same error "Mapping Not Found"
Cannot find what's wrong in YML project. I'll close topic.
I have entity AdminBundle\Entity\TuningPart\TuningPartImage which described in YML format.
Want to use Vich Uploader for Easyadmin
Tried use this filename _Resources/config/vichuploader/TuningPart.TuningPartImage.yml and _Resources/config/vichuploader/TuningPartImage.yml. No difference. Still receiving error
Mapping not found for field "imageFile"
. Tried to create incorrect YML but there is no errors. Seems file hasn't been imported.