dynamic download(File file, {String filename})

Sends a download as a response.

Source

download(File file, {String filename}) {
  header("Content-Disposition",
      'Content-Disposition: attachment; filename="${filename ?? file.path}"');
  header(HttpHeaders.CONTENT_TYPE, lookupMimeType(file.path));
  header(HttpHeaders.CONTENT_LENGTH, file.lengthSync().toString());
  responseData.add(file.readAsBytesSync());
}