downloadFile method

  1. @override
Future<String> downloadFile({
  1. required String remotePath,
  2. required String localPath,
})
override

Downloads a file from a remotePath to a localPath on the device.

Implementation

@override
Future<String> downloadFile({
  required String remotePath,
  required String localPath,
}) {
  return _executeRequest(
    () async {
      final response = await client.pull(remotePath,
          isAppFolder:
              MultiCloudStorage.cloudAccess == CloudAccessType.appStorage);

      if (response.statusCode == 404) {
        throw NotFoundException(response.message ?? response.toString());
      }
      if (response.message?.contains('SocketException') ?? false) {
        throw NoConnectionException(response.message ?? response.toString());
      }
      final file = File(localPath);
      if (response.bodyBytes == null) {
        throw Exception(response.message);
      } else {
        await file.writeAsBytes(response.bodyBytes!);
      }
      return localPath; // Return local path on success.
    },
    operation: 'downloadFile from $remotePath',
  );
}