downloadFile method

  1. @override
Future<String?> downloadFile(
  1. String url,
  2. Map<String, dynamic> body, {
  3. String fallbackFilename = "file",
})
override

Implementation

@override
Future<String?> downloadFile(String url, Map<String, dynamic> body, {String fallbackFilename = "file"}) async {
  http.Response response = await http.post(
    Uri.parse(url),
    body: body,
  );

  FileInfo fileInfo = parseFileInfo(response.headers["content-disposition"]) ?? FileInfo(fallbackFilename, "");
  var blob = html.Blob([response.bodyBytes], response.headers["content-type"], "native");
  html.AnchorElement(href: html.Url.createObjectUrl(blob).toString())
    ..setAttribute("download", "${fileInfo.fileName}${fileInfo.fileExtension}")
    ..click();
  return null;
}