pub struct FileResponse { /* private fields */ }Expand description
File response for serving files.
Supports:
- Automatic content-type inference from file extension
- Optional Content-Disposition for downloads
- Streaming for large files
§Examples
ⓘ
use fastapi_core::response::FileResponse;
use std::path::Path;
// Inline display (images, PDFs in browser)
let response = FileResponse::new(Path::new("image.png"));
// Force download with custom filename
let response = FileResponse::new(Path::new("data.csv"))
.download_as("report.csv");Implementations§
Source§impl FileResponse
impl FileResponse
Sourcepub fn new(path: impl Into<PathBuf>) -> Self
pub fn new(path: impl Into<PathBuf>) -> Self
Create a new file response.
The content-type will be inferred from the file extension.
Sourcepub fn content_type(self, content_type: impl Into<String>) -> Self
pub fn content_type(self, content_type: impl Into<String>) -> Self
Override the content-type.
Sourcepub fn download_as(self, filename: impl Into<String>) -> Self
pub fn download_as(self, filename: impl Into<String>) -> Self
Set as download with the specified filename.
Sets Content-Disposition: attachment; filename=“…”
Sourcepub fn into_response_sync(self) -> Response
pub fn into_response_sync(self) -> Response
Trait Implementations§
Source§impl Debug for FileResponse
impl Debug for FileResponse
Source§impl IntoResponse for FileResponse
impl IntoResponse for FileResponse
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Convert into a response.
Auto Trait Implementations§
impl Freeze for FileResponse
impl RefUnwindSafe for FileResponse
impl Send for FileResponse
impl Sync for FileResponse
impl Unpin for FileResponse
impl UnwindSafe for FileResponse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).