downloadBytes method

Future<Uint8List> downloadBytes(
  1. String url
)

Downloads content as bytes from a URL.

Performs a GET request to download content and returns the raw bytes. Useful for downloading images, documents, or other binary content.

Parameters:

  • url: The URL to download content from (can be absolute or relative to baseUrl)

Returns: The downloaded content as Uint8List

Throws: DioException if the download fails

Example:

final bytes = await client.downloadBytes('/files/document.pdf');
final file = File('document.pdf');
await file.writeAsBytes(bytes);

Implementation

Future<Uint8List> downloadBytes(String url) async {
  try {
    final response = await dio.get(
      url,
      options: Options(responseType: ResponseType.bytes),
    );
    return response.data;
  } catch (e) {
    rethrow;
  }
}