Skip to content

Request Forms and Files

from justapi import JustAPIApp, UploadFile, File, Form
app = JustAPIApp()
@app.post("/items/")
async def create_item(
name: str = Form(...),
description: str = Form(""),
image: UploadFile = File(None),
):
result = {"name": name, "description": description}
if image:
content = await image.read()
result["image_size"] = len(content)
return result
@app.post("/upload/")
async def upload_with_metadata(
title: str = Form(...),
tags: list[str] = Form([]),
files: list[UploadFile] = File(...),
):
return {
"title": title,
"tags": tags,
"file_count": len(files),
"filenames": [f.filename for f in files],
}