download method
Download a file from the given URL to a local path.
url - The URL to download from.
savePath - The local path to save the file to.
onProgress - Optional callback for download progress.
deleteOnError - Whether to delete the file if download fails (default: true).
Example:
await api.download(
'https://example.com/file.pdf',
savePath: '/path/to/save/file.pdf',
onProgress: (received, total) {
if (total != -1) {
print('Progress: ${(received / total * 100).toStringAsFixed(0)}%');
}
},
);
Implementation
Future<Response> download(
String url, {
required String savePath,
ProgressCallback? onProgress,
bool deleteOnError = true,
CancelToken? cancelToken,
Map<String, dynamic>? queryParameters,
Options? options,
}) async {
return await dio.download(
url,
savePath,
onReceiveProgress: onProgress,
deleteOnError: deleteOnError,
cancelToken: cancelToken,
queryParameters: queryParameters,
options: options,
);
}