downloadBytesFile function

void downloadBytesFile(
  1. String filename,
  2. List<int> bytes,
  3. String mimeType
)

Implementation

void downloadBytesFile(String filename, List<int> bytes, String mimeType) {
  final uint8 = Uint8List.fromList(bytes);
  final blob = web.Blob(
    [uint8.toJS].toJS,
    web.BlobPropertyBag(type: mimeType),
  );
  final url = web.URL.createObjectURL(blob);
  final anchor = web.HTMLAnchorElement()
    ..href = url
    ..download = filename;
  web.document.body?.append(anchor);
  anchor.click();
  web.document.body?.removeChild(anchor);
  web.URL.revokeObjectURL(url);
}