static_files#
- class litestar.static_files.StaticFiles#
Bases:
object
ASGI App that handles file sending.
- __init__(is_html_mode: bool, directories: Sequence[PathType], file_system: FileSystemProtocol, send_as_attachment: bool = False) None #
Initialize the Application.
- Parameters:
is_html_mode – Flag dictating whether serving html. If true, the default file will be
index.html
.directories – A list of directories to serve files from.
file_system – The file_system spec to use for serving files.
send_as_attachment – Whether to send the file with a
content-disposition
header ofattachment
orinline
- async get_fs_info(directories: Sequence[PathType], file_path: PathType) tuple[Path, FileInfo] | tuple[None, None] #
Return the resolved path and a
stat_result
.- Parameters:
directories – A list of directory paths.
file_path – A file path to resolve
- Returns:
A tuple with an optional resolved
Path
instance and an optionalstat_result
.
- class litestar.static_files.StaticFilesConfig#
Bases:
object
Configuration for static file service.
To enable static files, pass an instance of this class to the
Litestar
constructor using the ‘static_files_config’ key.- html_mode: bool = False#
Flag dictating whether serving html.
If true, the default file will be ‘index.html’.
- file_system: Any = <litestar.file_system.BaseLocalFileSystem object>#
The file_system spec to use for serving files.
Notes
- A file_system is a class that adheres to the
- You can use any of the file systems exported from the
[fsspec](https://filesystem-spec.readthedocs.io/en/latest/) library for this purpose.
- __init__(path: str, directories: list[PathType], html_mode: bool = False, name: str | None = None, file_system: Any = <litestar.file_system.BaseLocalFileSystem object>, opt: dict[str, Any] | None = None, guards: list[Guard] | None = None, exception_handlers: ExceptionHandlersMap | None = None, send_as_attachment: bool = False) None #
- opt: dict[str, Any] | None = None#
A string key dictionary of arbitrary values that will be added to the static files handler.
- exception_handlers: ExceptionHandlersMap | None = None#
A dictionary that maps handler functions to status codes and/or exception types.
- to_static_files_app() ASGIRouteHandler #
Return an ASGI app serving static files based on the config.
- Returns: