EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

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.

Open yazchd opened this issue 1 year ago • 2 comments

          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

yazchd avatar Feb 27 '24 12:02 yazchd

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 avatar Feb 27 '24 12:02 yazchd

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',
            ]))

SeapalDavid avatar Aug 28 '24 19:08 SeapalDavid

The question is why there cannot be a generic FileField class and a subsequent child, ImageField with properly set up expectations on the constraints.

bytes-commerce avatar Nov 27 '24 13:11 bytes-commerce

We're working on fixing/improving this feature. I need it myself, so I'll try to have this ready soon. Thanks.

javiereguiluz avatar Dec 31 '24 13:12 javiereguiluz