fromPath static method

Response fromPath(
  1. String path, {
  2. bool download = false,
  3. String? fileName,
  4. Map<String, String> headers = const {},
})

Streams the file at path from disk without holding it in memory.

A single Range request is answered with 206 Partial Content, so media can be seeked and interrupted downloads resumed. With download the browser saves the file, as fileName or by default under its own name. A path that is not a file gets a 404.

path is read as given: never build it from request input without confining it to a directory you mean to serve.

Implementation

static Response fromPath(
  String path, {
  bool download = false,
  String? fileName,
  Map<String, String> headers = const {},
}) => _FileResponse(
  path,
  download: download,
  fileName: fileName,
  headers: headers,
);