UploadFile API
UploadFile Object
Section titled “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, FileProperties
Section titled “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
Section titled “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 |
@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()
Section titled “File()”Declare a file parameter:
File( default=..., # Use ... for required description=None, # OpenAPI description)Form()
Section titled “Form()”Declare a form field parameter:
Form( default=..., description=None,)See Also
Section titled “See Also”- File Uploads Tutorial — Usage guide
- Dependency Injection API — File and Form extractors