enrolPhoto method

Future<String> enrolPhoto({
  1. required String token,
  2. required Image image,
  3. required PhotoSource source,
  4. Map<String, String> additionalOptions = const {},
})

Implementation

Future<String> enrolPhoto({
  required String token,
  required Image image,
  required PhotoSource source,
  Map<String, String> additionalOptions = const {},
}) async {
  final request =
      http.MultipartRequest(
          'POST',
          Uri.parse('$_normalizedBaseUrl/claim/enrol/image'),
        )
        ..fields['api_key'] = apiKey
        ..fields['secret'] = secret
        ..fields['rotation'] = '0'
        ..fields['token'] = token
        ..fields['source'] = source.stringValue
        ..fields.addAll(additionalOptions)
        ..files.add(
          http.MultipartFile.fromBytes(
            'image',
            encodeJpg(image),
            filename: 'image.jpg',
            contentType: MediaType.parse('image/jpeg'),
          ),
        );

  final response = await request.send();
  if (response.statusCode != 200) {
    final body = await response.stream.bytesToString();
    throw Exception('Error ${response.statusCode}: $body');
  }

  final bytes = await response.stream.toBytes();
  final json = jsonDecode(utf8.decode(bytes));

  return json['token'];
}