All Strawberry integrations support multipart uploads as described in the
GraphQL multipart request specification .
This includes support for uploading single files as well as lists of files.
Uploads can be used in mutations via the Upload scalar. The type passed at
runtime depends on the integration:
In order to have the correct runtime type in resolver type annotations you can
set a scalar override based on the integrations above. For example with
Starlette:
ASGI / FastAPI / Starlette
Since these integrations use asyncio for communication, the resolver must be
async.
Additionally, these servers rely on the python-multipart package, which is not
included by Strawberry by default. It can be installed directly, or, for
convenience, it is included in extras: strawberry[asgi] (for ASGI/Starlette)
or strawberry[fastapi] (for FastAPI). For example:
if using Pip, pip install 'strawberry[fastapi]'
if using Poetry, strawberry = { version = "...", extras = ["fastapi"] } in
pyproject.toml .
Example:
Sanic / Flask / Django / Channels / AIOHTTP
Example:
Sending file upload requests
The tricky part is sending the HTTP request from the client because it must
follow the GraphQL multipart request specifications mentioned above.
The multipart/form-data POST requestβs data must include:
operations key for GraphQL request with query and variables
map key with mapping some multipart-data to exact GraphQL variable
and other keys for multipart-data which contains binary data of files
Assuming you have your schema up and running, here there are some requests
examples: