download method

  1. @override
Future<ParseXFile> download({
  1. ProgressCallback? progressCallback,
})
override

Implementation

@override
Future<ParseXFile> download({ProgressCallback? progressCallback}) async {
  if (url == null) {
    return this;
  }

  progressCallback ??= _progressCallback;

  _cancelToken = CancelToken();

  if (parseIsWeb) {
    final ParseNetworkByteResponse response = await _client.getBytes(
      url!,
      onReceiveProgress: progressCallback,
      cancelToken: _cancelToken,
    );

    if (response.bytes != null) {
      file = XFile.fromData(response.bytes as Uint8List);
    }
  } else {
    file = XFile('${ParseCoreData().fileDirectory}/$name');
    await File(file!.path).create();

    final ParseNetworkByteResponse response = await _client.getBytes(
      url!,
      onReceiveProgress: progressCallback,
      cancelToken: _cancelToken,
    );
    await File(file!.path).writeAsBytes(response.bytes!);
  }

  return this;
}