How to make File type input optional #428
Unanswered
ashrane111
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am taking two inputs of file type for an API. I want to make it so that the input fields can be optional. But it seems I cannot make file type input optional.
I have tried passing parameters like "nullable=True" and "allow_none=True" . What this does is, it removes the option to upload the file.
I have also set docs_ui = "elements". If I use the previous UI which is provided by swagger, it does give me an option to send empty value for file upload.
Another solution to this is,
in APIFlask.fields.File
def _deserialize(self, value, attr, data, **kwargs) -> t.Any:
from werkzeug.datastructures import FileStorage
if not isinstance(value, FileStorage):
raise self.make_error('invalid')
return value
Here if there is an option to return None rather than raise an error, it would work
Any help would be appreciated
Beta Was this translation helpful? Give feedback.
All reactions