Skip to content

How to declare a list of allowed mime-types for a file (form data)? #228

@rmeissn

Description

@rmeissn

I can easily declare:

class example(BaseModel):
    file: flask_openapi3.FileStorage

that generates a file upload form within e.g. swagger. Now I'd like to declare a list of allowed mime-types, that are checked by pydantic and are also used by the OS file-chooser to restrict shown files.
I wasn't able to find any information on how to do so, thus I'm seeking for help through this issue.

See https://swagger.io/docs/specification/v3_0/describing-request-body/file-upload/

I can easily add an additional field file_type: Literal["image/png"] = Field(default="image/png"), but this will only show an additional selection field, which does not influence the OSs file chooser or validation of the file within the FileStorage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions