Skip to content

[Validator] Add support for SVG files to image validation constraint #15460

Closed
@keichinger

Description

@keichinger

With the rise of SVG images all over the web I think it's pretty fair to say that having support for the already existing Image validator constraint would benefit everyone.

Let's have a look at the following scenario where we'd like to give the opportunity to someone to upload either a GIF, JPEG, PNG or an SVG.

# validation.yml

AppBundle\Entity\MyEntity:
    properties:
        # ...
        file:
            - Image:
                mimeTypes:
                    - image/gif
                    - image/jpeg
                    - image/png
                    - image/svg+xml
                minWidth: 1920
                minHeight: 1080
                # ...

The MIME type Google Chrome is sending matches images/svg+xml and still I'm getting the following error message: "This file is not a valid image."

A solution to this problem would be to write a custom validation constraint. However, I'm pretty sure that this is one of the things that might be needed more often in the future so the best place for it is inside the Symfony Core.

Opinions?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions