flask-openapi3 icon indicating copy to clipboard operation
flask-openapi3 copied to clipboard

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

Open rmeissn opened this issue 5 months ago • 1 comments

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.

rmeissn avatar Jun 27 '25 09:06 rmeissn

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.

luolingchun avatar Jun 30 '25 09:06 luolingchun