Storage

Use ctx.storage as a standardized, universal interface to read and write files without worrying about the underlying storage system. It is backed by fsspec(opens in new tab).

Example

python
from longlink import Context
​
async def write_report(ctx: Context) -> None:
with ctx.storage.open("reports/example.txt", "wb") as f:
f.write(b"hello")

Previews and downloads

Use ctx.file() to preview a file in the browser, or ctx.download() to download it.

python
from fastapi import APIRouter, Response
from longlink import Context
​
router = APIRouter()
​
​
@router.get("/reports/preview")
async def preview_report(ctx: Context) -> Response:
"""Serve a stored report for browser preview."""
​
# Return an inline response with a friendly display name.
return ctx.file("reports/latest.pdf", filename="report.pdf")
​
​
@router.get("/reports/download")
async def download_report(ctx: Context) -> Response:
"""Serve a stored report as a download."""
​
# Use the storage path's basename as the download filename.
return ctx.download("reports/latest.pdf")