mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-26 14:58:42 -05:00
* 🌐 Refactor file structure to support internationalization * ✅ Update tests changed after i18n * 🔀 Merge Typer style from master * 🔧 Update MkConfig with Typer-styles * 🎨 Format mkdocs.yml with cannonical form * 🎨 Format mkdocs.yml * 🔧 Update MkDocs config * ➕ Add docs translation scripts dependencies * ✨ Add Typer scripts to handle translations * ✨ Add missing translation snippet to include * ✨ Update contributing docs, add docs for translations * 🙈 Add docs_build to gitignore * 🔧 Update scripts with new locations and docs scripts * 👷 Update docs deploy action with translations * 📝 Add note about languages not supported in the theme * ✨ Add first translation, for Spanish
1.3 KiB
1.3 KiB
Request Forms and Files
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.
E.g. `pip install python-multipart`.
Import File and Form
{!../../../docs_src/request_forms_and_files/tutorial001.py!}
Define File and Form parameters
Create file and form parameters the same way you would for Body or Query:
{!../../../docs_src/request_forms_and_files/tutorial001.py!}
The files and form fields will be uploaded as form data and you will receive the files and form fields.
And you can declare some of the files as bytes and some as UploadFile.
!!! warning
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.
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.