save static method
Starts a browser download for bytes using fileName.
Implementation
static Future<String> save(Uint8List bytes, String fileName) async {
final mimeType = _mimeType(fileName);
final blob = web.Blob(
[bytes.toJS].toJS,
web.BlobPropertyBag(type: mimeType),
);
final url = web.URL.createObjectURL(blob);
final anchor = web.document.createElement('a') as web.HTMLAnchorElement
..href = url
..download = fileName;
try {
web.document.body?.appendChild(anchor);
anchor.click();
} finally {
anchor.remove();
Timer(const Duration(seconds: 1), () => web.URL.revokeObjectURL(url));
}
return 'Browser download started: $fileName';
}