How can I upload pdf files in easy admin? I have tried the same procedure as with the images and it has not worked for me.
How can I upload pdf files in easy admin? I have tried the same procedure as with the images and it has not worked for me.
HELP ME. Thank you
Originally posted by @juani0824 in https://github.com/EasyCorp/EasyAdminBundle/issues/3434#issuecomment-774545951
You can uploads PDF files by using : use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
You need to add the following lines in your code
public function configureFields(string $pageName): iterable
{
return [
TextField::new('firstname'),
TextField::new('lastname'),
TextField::new('email')
ImageField::new('pdf')
->setFormType(FileUploadType::class) // this function
->setBasePath('uploads/pdf/')
->setUploadDir('public/uploads/pdf/')
->onlyOnIndex()
->setFormTypeOptions(['attr' => [ // and this function
'accept' => 'application/pdf'
]
]),
TextField::new('pdfFile')->setFormType(VichImageType::class),
];
yazchd method didnt work with my project and i fixed by doing it like this
yield ImageField::new('media', 'Ver Documentos')
->hideOnIndex()
->hideOnDetail()
->setBasePath('docs/licitaciones')
->setUploadDir('public/docs/licitaciones')
->setFormTypeOption('multiple', true)
->setFileConstraints(new File([ // By adding this constraint i was able to upload any kind of file
'mimeTypes' => [
'application/pdf',
'application/x-pdf',
'application/msword',
'application/vnd.ms-excel'
],
'mimeTypesMessage' => 'Documento no válido, solo se permiten PDF, DOC o XLS',
]))
The question is why there cannot be a generic FileField class and a subsequent child, ImageField with properly set up expectations on the constraints.
We're working on fixing/improving this feature. I need it myself, so I'll try to have this ready soon. Thanks.