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
pythonfrom longlink import Contextasync 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.
pythonfrom fastapi import APIRouter, Responsefrom longlink import Contextrouter = 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")