file method
Serves a file from the local filesystem.
Automatically detects the content-type and uses efficient streaming.
Implementation
Response file(String path) {
final f = File(path);
if (!f.existsSync()) {
return json(<String, String>{'message': 'File not found'}, status: 404);
}
final mimeType = lookupMimeType(path) ?? 'application/octet-stream';
return Response(
body: f.openRead(),
statusCode: 200,
headers: <String, String>{'content-type': mimeType},
);
}