download method

Future<Response> download(
  1. String url, {
  2. required String savePath,
  3. ProgressCallback? onProgress,
  4. bool deleteOnError = true,
  5. CancelToken? cancelToken,
  6. Map<String, dynamic>? queryParameters,
  7. Options? options,
})

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,
  );
}