downloadFile method

  1. @override
Future<bool> downloadFile(
  1. String fileId,
  2. String saveName, {
  3. String? bucketId,
})
override

Implementation

@override
Future<bool> downloadFile(String fileId, String saveName,
    {String? bucketId}) async {
  try {
    if (kIsWeb) {
      final Uint8List? targetBytes = await getFileBytes(fileId);

      String targetUrl = Url.createObjectUrlFromBlob(Blob([targetBytes]));
      AnchorElement(href: targetUrl)
        ..setAttribute("download", saveName)
        ..click();
      Url.revokeObjectUrl(targetUrl);

      return true;
    }
    return true;
  } catch (e) {
    //print('downloadFile error:$e');
    logger.severe('downloadFile error:$e');
    return false;
  }
}