downloadFile method
This method allows to download the file with fileId
and fileName
from channel channel
It returns file content in bytes format List<int>
.
Provided cipherKey
overrides Keyset.cipherKey.
If keyset
is not provided, then it tries to obtain a keyset using
name.
If that fails, then it uses the default keyset.
If that fails as well, then it will throw InvariantException.
Implementation
Future<DownloadFileResult> downloadFile(
String channel, String fileId, String fileName,
{CipherKey? cipherKey, Keyset? keyset, String? using}) async {
keyset ??= _core.keysets[using];
return defaultFlow<DownloadFileParams, DownloadFileResult>(
keyset: keyset,
core: _core,
params: DownloadFileParams(getFileUrl(channel, fileId, fileName)
.replace(scheme: '', host: '')),
deserialize: false,
serialize: (object, [_]) => DownloadFileResult.fromJson(object,
cipherKey: cipherKey ?? keyset!.cipherKey,
decryptFunction: cipherKey != null ||
!(keyset?.cipherKey ==
_core.keysets.defaultKeyset.cipherKey) ||
!(_core.crypto is CryptoModule)
? _core.crypto.decryptFileData
: _core.crypto.decrypt));
}