diff --git a/lib/src/api/default_api.dart b/lib/src/api/default_api.dart index 7d9c266..4ab28fb 100644 --- a/lib/src/api/default_api.dart +++ b/lib/src/api/default_api.dart @@ -3,6 +3,7 @@ // import 'dart:async'; +import 'dart:typed_data'; import 'package:dio/dio.dart'; @@ -391,9 +392,9 @@ class DefaultApi { /// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress /// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress /// - /// Returns a [Future] containing a [Response] with a [JsonObject] as data + /// Returns a [Future] containing a [Response] with a [Uint8List] as data /// Throws [DioError] if API call or serialization fails - Future> getAsset({ + Future> getAsset({ required String fid, CancelToken? cancelToken, ValidateStatus? validateStatus, @@ -404,9 +405,10 @@ class DefaultApi { final _options = Options( method: 'GET', validateStatus: validateStatus, + responseType: ResponseType.bytes, ); - final _response = await _dio.request( + final _response = await _dio.request>( _path, options: _options, cancelToken: cancelToken, @@ -414,8 +416,20 @@ class DefaultApi { onReceiveProgress: onReceiveProgress, ); - return Response( - data: _response, + final respData = _response.data; + if (respData == null) { + throw DioError( + requestOptions: _options.compose( + _dio.options, + _path, + ), + type: DioErrorType.unknown, + error: 'Response was null', + ); + } + + return Response( + data: Uint8List.fromList(respData), headers: _response.headers, isRedirect: _response.isRedirect, requestOptions: _response.requestOptions, diff --git a/pubspec.yaml b/pubspec.yaml index a16e296..2cb2e11 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: tuuli_api -version: 1.0.1 +version: 1.0.2 description: OpenAPI API client homepage: homepage