Q: Image not uploading in DIO 4 and above Greeting everyone, my image is not uploading to my server when i update to DIO 4.0.0 and above. The same code works for DIO version below 4.0.0 . Below is the upload code. Kindly help me out. Thanks
Future<dynamic> upload(String url, BuildContext context,
      {List<File> files,
      Map body,
      FileCount count = FileCount.MULTIPLE,
      authorize = true}) async {

    BaseOptions options = await getOptions(validate: authorize);

    dynamic response, serverResponse;

    List<MultipartFile> uploadFiles = [];

    FormData requestData;


    try {
      Dio dio = new Dio(options)..interceptors.add(Logging());

      (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
          (client) {
        SecurityContext sc = new SecurityContext();
        HttpClient httpClient = new HttpClient(context: sc);
        //allow all cert
        httpClient.badCertificateCallback =
            (X509Certificate cert, String host, int port) => true;
        return httpClient;
      };

      // add files to uploadFiles array
      if (files.length > 0) {
        for (var index = 0; index < files.length; index++) {
          MultipartFile file = MultipartFile.fromFileSync(files[index].path,
              filename: basename(files[index].path),contentType:MediaType.parse('image/jpg'));
          uploadFiles.add(file);
        }

        print("file the request: $uploadFiles");

        requestData = FormData.fromMap({"file": uploadFiles});
      } else {
        requestData = FormData();
      }

      body.forEach((key, value) {
        MapEntry<String, String> data = new MapEntry(key, '$value');
        requestData.fields.add(data);
      });

      print("sending the request: ${uploadFiles.asMap().values}");



      serverResponse = await dio.post(
        url,
        data: requestData,
        options: new Options(contentType: 'multipart/form-data'),
        onSendProgress: (int sent, int total) {
          print('$sent $total');
        },
      );

      print("Server Replied: $serverResponse}");

      print(serverResponse.data);

      //check for connection errors
      if (serverResponse.statusCode < 200 || serverResponse.statusCode > 400) {
        return _decoder.convert(
            '{"success":false,"message":"${LocalText.of(context).load("error_executing_request")}"}');
      }

      response = _decoder.convert(serverResponse.data);

      print("Response: $response");
    } on DioError catch (e) {
      // The request was made and the server responded with a status code
      // that falls out of the range of 2xx and is also not 304.
      if (e.response != null) {
        print(e.response.data);
        print(e.response.headers);
        // print(e.response.request);
        response = _decoder.convert(
            '{"success":false,"message":"${LocalText.of(context).load("server_error")}"}');
      } else {
        // Something happened in setting up or sending the request that triggered an Error
        print(e.message);
        response =
            _decoder.convert('{"success":false,"message":"' + e.message + '"}');
      }
    } catch (error) {
      return _decoder.convert(
          '{"success":false,"message":"${LocalText.of(context).load("error_executing_request")}"}');
    }
    return response;
  }

