downloadFile static method
Implementation
static Future<bool> downloadFile(SaveRequest request) async {
bool success = false;
try {
String url = URL.createObjectURL(
Blob(
<JSUint8Array>[(request.bytes ?? Uint8List(0)).toJS].toJS,
BlobPropertyBag(type: request.mimeType),
),
);
Document htmlDocument = document;
HTMLAnchorElement anchor =
htmlDocument.createElement('a') as HTMLAnchorElement;
anchor.href = url;
anchor.style.display = 'none';
anchor.download = request.name + request.fileExtension;
document.body!.add(anchor);
anchor.click();
anchor.remove();
URL.revokeObjectURL(url);
success = true;
} catch (e) {
rethrow;
}
return success;
}