uploadOTAImage method

Future<String> uploadOTAImage(
  1. String imageName,
  2. String base64FWImage, [
  3. String? imageType
])

Uploads OTA Image and returns its URL.

The firmware image, base64FWImage, must be a base64 encoded string.

Implementation

Future<String> uploadOTAImage(String imageName, String base64FWImage,
    [String? imageType]) async {
  final uri = _urlBase.getPath(_otaBase);

  final body = await JsonIsolate().encodeJson({
    'base64_fwimage': base64FWImage,
    'image_name': imageName,
    'type': imageType,
  });

  final resp = await post(
    uri,
    body: body,
    headers: {
      URLBase.authHeader: accessToken,
    },
  );
  final Map<String, dynamic> bodyResp =
      await JsonIsolate().decodeJson(resp.body);
  if (resp.statusCode != 200) {
    throw bodyResp['description'];
  }

  return bodyResp['image_url'];
}