fromPath static method

Future<StreamResponse> fromPath(
  1. String path, {
  2. int statusCode = 200,
  3. Map<String, dynamic>? headers,
  4. String? mimeType,
  5. String? charset,
  6. List<Cookie>? cookies,
})

Response that writes the contents of file at path to the response.

Implementation

static Future<StreamResponse> fromPath(
  String path, {
  int statusCode = 200,
  Map<String, dynamic>? headers,
  String? mimeType,
  String? charset,
  List<Cookie>? cookies,
}) async {
  final file = File(path);
  if (!await file.exists()) throw new Exception();
  return StreamResponse.fromFile(
    file,
    statusCode: statusCode,
    headers: headers,
    mimeType: mimeType ?? MimeTypes.ofFile(file),
    charset: charset,
    cookies: cookies,
  );
}