scanMultipart method

Future<BarcodeResponseList> scanMultipart(
  1. Uint8List fileBytes
)

Scan barcode from file in request body using POST requests with parameter in multipart form.

Implementation

Future<BarcodeResponseList> scanMultipart(Uint8List fileBytes) async {
  // ignore: prefer_final_locals
  Object? postBody;

  // create path and map variables
  final String requestPath = "/barcode/scan-multipart";

  // query params
  final List<QueryParam> queryParams = [];
  final Map<String, String> headerParams = {};
  final Map<String, String> formParams = {};

  final List<String> contentTypes = ["multipart/form-data"];

  final String contentType =
      contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
  final List<String> authNames = ["JWT"];

  MultipartRequestPlus mp =
      MultipartRequestPlus('POST', Uri.parse(requestPath));

  mp.files.add(MultipartFile.fromBytes("file", fileBytes.toList(),
      filename: "somefile.xyz"));

  postBody = mp;

  final response = await _apiClient.invokeAPI(
      requestPath,
      'POST',
      queryParams,
      postBody,
      headerParams,
      formParams,
      contentType,
      authNames);

  if (response.statusCode >= 400) {
    ApiErrorResponse error;
    try {
      error = _apiClient.deserialize(response.body, 'ApiErrorResponse');
    } catch (e) {
      throw ApiException(response.statusCode, response.body);
    }
    throw ApiException.withResponse(
        response.statusCode,
        response.reasonPhrase == null
            ? "Api response error"
            : response.reasonPhrase!,
        error);
  } else {
    return _apiClient.deserialize(response.body, 'BarcodeResponseList')
        as BarcodeResponseList;
  }
}