download method

Response download(
  1. String path, [
  2. String? filename
])

Forces a file download by setting the Content-Disposition header.

Implementation

Response download(String path, [String? filename]) {
  final res = file(path);
  if (res.statusCode != 200) return res;

  final name = filename ?? path.split(Platform.pathSeparator).last;
  return res.withHeaders(<String, String>{
    'content-disposition': 'attachment; filename="$name"',
  });
}