You can define files to be uploaded by the client using `File`.
+!!! info
+ To receive uploaded files, first install [`python-multipart`](https://andrew-d.github.io/python-multipart/).
+
+ E.g. `pip install python-multipart`.
+
+ This is because uploaded files are sent as "form data".
+
## Import `File`
Import `File` and `UploadFile` from `fastapi`:
You can define files and form fields at the same time using `File` and `Form`.
+!!! info
+ To receive uploaded files and/or form data, first install [`python-multipart`](https://andrew-d.github.io/python-multipart/).
+
+ E.g. `pip install python-multipart`.
+
## Import `File` and `Form`
```Python hl_lines="1"
When you need to receive form fields instead of JSON, you can use `Form`.
+!!! info
+ To use forms, first install [`python-multipart`](https://andrew-d.github.io/python-multipart/).
+
+ E.g. `pip install python-multipart`.
+
## Import `Form`
Import `Form` from `fastapi`:
## Run it
+!!! info
+ First install [`python-multipart`](https://andrew-d.github.io/python-multipart/).
+
+ E.g. `pip install python-multipart`.
+
+ This is because **OAuth2** uses "form data" for sending the `username` and `password`.
+
Run the example with:
```bash