You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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