flask-openapi3
flask-openapi3 copied to clipboard
How to declare a list of allowed mime-types for a file (form data)?
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.
Unfortunately, file uploads are integrated into form(multipart/form-data) to support additional fields.
I also didn't find any evidence that the openapi support system restricts the display of files.