Skip to content

UploadFile API

Represents a file uploaded via multipart/form-data. Files are streamed to temporary files by the Rust multer parser.

from justapi import UploadFile, File
Attribute Type Description
filename str Original filename from the client
content_type str MIME type (e.g., image/png)
file str Path to the temporary file on disk
size int File size in bytes
Method Returns Description
.read() bytes Read file contents into memory
.write(data) int Write bytes to the temp file
.seek(pos) None Seek to position in the temp file
.close() None Close and clean up the temp file
@app.post("/upload")
async def upload(request, file: UploadFile = File(...)):
content = await file.read()
return {
"name": file.filename,
"type": file.content_type,
"size": file.size,
"content": content.decode(),
}

Declare a file parameter:

File(
default=..., # Use ... for required
description=None, # OpenAPI description
)

Declare a form field parameter:

Form(
default=...,
description=None,
)