download method

Future<void> download(
  1. File file, {
  2. String? name,
  3. bool inline = false,
  4. String? contentType,
})

Sends a file download response.

Implementation

Future<void> download(
  File file, {
  String? name,
  bool inline = false,
  String? contentType,
}) async {
  if (_sent) return;

  final filename = name ?? file.uri.pathSegments.last;
  final disposition = inline ? 'inline' : 'attachment';

  _headers.setHeader(
    'Content-Disposition',
    '$disposition; filename="$filename"',
  );

  await sendFile(file, contentType: contentType);
}