getFileUrl method
Returns Uri to download the file with fileId
and fileName
from channel
.
You can download the file by making a GET request to returned Uri.
If the file is encrypted, you will have to decrypt it on your own.
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
Uri getFileUrl(String channel, String fileId, String fileName,
{Keyset? keyset, String? using}) {
keyset ??= _core.keysets[using];
var pathSegments = [
'v1',
'files',
keyset.subscribeKey,
'channels',
channel,
'files',
fileId,
fileName
];
var queryParams = {
'pnsdk': 'PubNub-Dart/${Core.version}',
'uuid': keyset.uuid.value,
if (keyset.secretKey != null)
'timestamp': '${Time().now()!.millisecondsSinceEpoch ~/ 1000}',
if (keyset.authKey != null) 'auth': keyset.authKey!
};
if (keyset.secretKey != null) {
queryParams.addAll(
{'signature': computeSignature(keyset, pathSegments, queryParams)});
}
return Uri(
scheme: 'https',
host: 'ps.pndsn.com',
pathSegments: pathSegments,
queryParameters: queryParams,
);
}