postImage static method

Future postImage(
  1. File image,
  2. String field
)

Implementation

static Future<dynamic> postImage(File image, String field) async {
  var uri = Uri.parse(UrlConfig.urlAIvehicle);
  debugPrint('Start: ${DateTime.now().millisecondsSinceEpoch} +' '+ ${image.path}');
  Map<String, String> headers = <String, String>{'x-auth-secret-key': UrlConfig.secretKey};

  var request = http.MultipartRequest('POST', uri)
    ..headers.addAll(headers)
    ..files.add(await http.MultipartFile.fromPath(field, image.path));
  // request..fields.addAll({field: image.path});
  var response = await request.send();
  final respStr = await response.stream.bytesToString();
  debugPrint('respStr: ${jsonDecode(respStr)}');
  return jsonDecode(respStr);
}