I work on a Symfony 6.0.9 website with EasyAdmin to handle the administration panel. I've got an entity User and an entity MediaObject that can be an image for example. The User has a property $profilePicture which is a MediaObject. In EasyAdmin, I've got a UserCrudController like that :
class UserCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return User::class;
}
public function configureCrud(Crud $crud): Crud
{
...
}
public function configureFields(string $pageName): iterable
{
return [
...
FormField::addPanel('Pictures')->renderCollapsed(),
ImageField::new('profilePicture.filePath')
->setBasePath('/media')
->setUploadDir('public/media')
->setUploadedFileNamePattern('profilePicture.[extension]')
->setLabel('Profile picture')
->setColumns(4),
...
];
}
}
In my app/config/services.yaml file, I've set :
parameters:
app.path.media_object: /media
In my app/config/packages/vich_uploader.yaml file, I've set :
vich_uploader:
db_driver: orm
mappings:
media_object:
uri_prefix: '%app.path.media_object%'
upload_destination: '%kernel.project_dir%/public%app.path.media_object%'
When I'm in my localhost (so in dev env), everything works just fine. When I build and deploy on Heroku, I works fine. But when I try to edit an user, I've got this error message in Heroku's logs :
[critical] Uncaught PHP Exception Symfony\Component\OptionsResolver\Exception\InvalidArgumentException: "An error has occurred resolving the options of the form "EasyCorp\Bundle\EasyAdminBundle\Form\Type\FileUploadType": Invalid upload directory "/app/public/media/" it does not exist or is not writable." at /app/vendor/symfony/form/ResolvedFormType.php line 93
I don't understand what I've done wrong. Thanks for helping me ! ;)