downloadStream method

Stream<Uint8List> downloadStream(
  1. String path, {
  2. TransformOptions? transform,
  3. Map<String, String>? queryParams,
  4. String? cacheNonce,
})

Downloads a file as a byte stream for memory-efficient handling of large files.

Unlike download, the response body is not buffered into a Uint8List; the stream yields the bytes as they arrive. The request is sent when the stream is listened to, and a non-success response surfaces as a StorageException on the stream before any bytes are emitted.

path is the file path to be downloaded, including the path and file name. For example downloadStream('folder/image.png').

transform download a transformed variant of the image with the provided options.

queryParams additional query parameters to be added to the URL.

cacheNonce adds a cacheNonce query parameter to bypass CDN caching for a specific file version.

Implementation

Stream<Uint8List> downloadStream(
  String path, {
  TransformOptions? transform,
  Map<String, String>? queryParams,
  String? cacheNonce,
}) {
  final fetchUrl = _downloadUri(
    path,
    transform: transform,
    queryParams: queryParams,
    cacheNonce: cacheNonce,
  );

  return _storageFetch.getStream(
    fetchUrl.toString(),
    options: FetchOptions(headers, noResolveJson: true),
  );
}