UploadFile Object
Represents a file uploaded via multipart/form-data. Files are streamed to temporary files by the Rust multer parser.
from justapi import UploadFile, File
Properties
| 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 |
Methods
| 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 |
Usage
@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(),
}
File()
Declare a file parameter:
File(
default=..., # Use ... for required
description=None, # OpenAPI description
)
Form()
Declare a form field parameter:
Form(
default=...,
description=None,
)
See Also
- File Uploads Tutorial — Usage guide
- Dependency Injection API — File and Form extractors