2018-12-15 12:10:35 +04:00
You can define files and form fields at the same time using `File` and `Form` .
## Import `File` and `Form`
```Python hl_lines="1"
2018-12-21 16:22:33 +04:00
{!./src/request_forms_and_files/tutorial001.py!}
2018-12-15 12:10:35 +04:00
` ``
## Define ` File` and ` Form` parameters
Create file and form parameters the same way you would for ` Body` or ` Query`:
2019-03-03 20:52:37 +04:00
` ``Python hl_lines="8"
2018-12-21 16:22:33 +04:00
{!./src/request_forms_and_files/tutorial001.py!}
2018-12-15 12:10:35 +04:00
` ``
The files and form fields will be uploaded as form data and you will receive the files and form fields.
2019-03-03 20:52:37 +04:00
And you can declare some of the files as ` bytes` and some as ` UploadFile`.
2018-12-15 12:10:35 +04:00
!!! warning
2018-12-15 14:03:59 +04:00
You can declare multiple ` File` and ` Form` parameters in a path operation, but you can't also declare ` Body` fields that you expect to receive as JSON, as the request will have the body encoded using ` multipart/form-data` instead of ` application/json`.
2018-12-15 12:10:35 +04:00
This is not a limitation of **FastAPI**, it's part of the HTTP protocol.
## Recap
Use ` File` and ` Form` together when you need to receive data and files in the same request.