file¶
- class litestar.response.file.ASGIFileResponse[原始碼]¶
-
A low-level ASGI response, streaming a file as response body.
- __init__(*, background: BackgroundTask | BackgroundTasks | None = None, chunk_size: int = 1048576, content_disposition_type: Literal['attachment', 'inline'] = 'attachment', content_length: int | None = None, cookies: Iterable[Cookie] | None = None, encoding: str = 'utf-8', etag: ETag | None = None, file_info: FileInfo | None = None, file_path: str | PathLike | Path, file_system: BaseFileSystem, filename: str = '', headers: dict[str, str] | None = None, is_head_response: bool = False, media_type: MediaType | str | None = None, status_code: int | None = None) None[原始碼]¶
A low-level ASGI response, streaming a file as response body.
- 參數:
background¶ -- A background task or a list of background tasks to be executed after the response is sent.
chunk_size¶ -- The chunk size to use.
content_disposition_type¶ -- The type of the
Content-Disposition. Eitherinlineorattachment.content_length¶ -- The response content length.
cookies¶ -- The response cookies.
encoding¶ -- The response encoding.
etag¶ -- An etag.
file_info¶ -- A file info.
file_path¶ -- A path to a file.
file_system¶ -- A file system adapter.
filename¶ -- The name of the file.
headers¶ -- A dictionary of headers.
headers¶ -- The response headers.
is_head_response¶ -- A boolean indicating if the response is a HEAD response.
media_type¶ -- The media type of the file.
status_code¶ -- The response status code.
- class litestar.response.file.File[原始碼]¶
基底類別:
ResponseA response, streaming a file as response body.
- __init__(path: str | PathLike | Path, *, background: BackgroundTask | BackgroundTasks | None = None, chunk_size: int = 1048576, content_disposition_type: Literal['attachment', 'inline'] = 'attachment', cookies: ResponseCookies | None = None, encoding: str = 'utf-8', etag: ETag | None = None, file_info: FileInfo | None = None, file_system: str | BaseFileSystem | AbstractFileSystem | AbstractAsyncFileSystem | None = None, filename: str | None = None, headers: ResponseHeaders | None = None, media_type: Literal[MediaType.TEXT] | str | None = None, status_code: int | None = None) None[原始碼]¶
Send a file from a file system.
- 參數:
path¶ -- A file path in one of the supported formats.
background¶ -- A
BackgroundTaskinstance orBackgroundTasksto execute after the response is finished. Defaults to None.chunk_size¶ -- The chunk sizes to use when streaming the file. Defaults to 1MB.
content_disposition_type¶ -- The type of the
Content-Disposition. Eitherinlineorattachment.cookies¶ -- A list of
Cookieinstances to be set under the responseSet-Cookieheader.encoding¶ -- The encoding to be used for the response headers.
etag¶ -- An optional
ETaginstance. If not provided, an etag will be generated.file_info¶ -- The output of calling
file_system.infofile_system¶ -- The file system to load the file from. Instances of
BaseFileSystem,fsspec.spec.AbstractFileSystem,fsspec.asyn.AsyncFileSystemwill be used directly. If passed string, use it to look up the corresponding file system from theFileSystemRegistry. If not given, the file will be loaded fromdefaultfilename¶ -- An optional filename to set in the header.
headers¶ -- A string keyed dictionary of response headers. Header keys are insensitive.
media_type¶ -- A value for the response
Content-Typeheader. If not provided, the value will be either derived from the filename if provided and supported by the stdlib, or will default toapplication/octet-stream.status_code¶ -- An HTTP status code.
- to_asgi_response(request: Request, *, background: BackgroundTask | BackgroundTasks | None = None, cookies: Iterable[Cookie] | None = None, headers: dict[str, str] | None = None, is_head_response: bool = False, media_type: MediaType | str | None = None, status_code: int | None = None, type_encoders: TypeEncodersMap | None = None) ASGIFileResponse[原始碼]¶
Create an
ASGIFileResponseinstance.- 參數:
background¶ -- Background task(s) to be executed after the response is sent.
cookies¶ -- A list of cookies to be set on the response.
headers¶ -- Additional headers to be merged with the response headers. Response headers take precedence.
is_head_response¶ -- Whether the response is a HEAD response.
media_type¶ -- Media type for the response. If
media_typeis already set on the response, this is ignored.status_code¶ -- Status code for the response. If
status_codeis already set on the response, this istype_encoders¶ -- A dictionary of type encoders to use for encoding the response content.
- 回傳:
A low-level ASGI file response.