downloadFile method
Downloads a file from the cloud storage.
Implementation
@override
Future<String> downloadFile(
{required String remotePath, required String localPath}) async {
_checkAuth();
final response = await _dio.post(
'https://content.dropboxapi.com/2/files/download',
options: Options(
headers: {
'Dropbox-API-Arg': jsonEncode({'path': _normalizePath(remotePath)})
},
responseType: ResponseType.stream,
),
);
final file = File(localPath);
final sink = file.openWrite();
// Efficiently write the stream to the file
await sink.addStream(response.data.stream);
await sink.close();
return localPath;
}