Skip to content

Commit

Permalink
document how to use an optional file input (#1326)
Browse files Browse the repository at this point in the history
  • Loading branch information
toudi authored Oct 25, 2024
1 parent 9ff32ec commit e070fab
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/docs/guides/input/file-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,15 @@ this will expect from the client side to send data as `multipart/form-data with
def create_user(request, details: Form[UserDetails], files: File[list[UploadedFile]]):
return [details.dict(), [f.name for f in files]]
```

### Optional file input

If you would like the file input to be optional, all that you have to do is to pass `None` to the `File` type, like so:

```python
@api.post('/users')
def create_user(request, details: Form[UserDetails], avatar: UploadedFile = File(None)):
user = add_user_to_database(details)
if avatar is not None:
set_user_avatar(user)
```

0 comments on commit e070fab

Please sign in to comment.