streamContainerFileContent method

Stream<Uint8List> streamContainerFileContent(
  1. String containerId,
  2. String fileId
)

Stream the container file content as chunks (useful for large files).

Implementation

Stream<Uint8List> streamContainerFileContent(String containerId, String fileId) async* {
  final req = http.Request('GET', _resolve('/containers/$containerId/files/$fileId/content'))..headers.addAll(getHeaders({}) ?? {});
  final res = await httpClient.send(req);

  if (res.statusCode < 200 || res.statusCode >= 300) {
    final body = await res.stream.bytesToString();
    throw OpenAIRequestException(statusCode: res.statusCode, message: res.reasonPhrase ?? 'request failed', bodyPreview: body);
  }

  await for (final chunk in res.stream) {
    yield Uint8List.fromList(chunk);
  }
}