executeUpload method

Future<String> executeUpload(
  1. String _method,
  2. SellonMethod sellonMethod,
  3. Parameter _parameter, {
  4. String? urlFix,
})

Implementation

Future<String> executeUpload(
    String _method, SellonMethod sellonMethod, Parameter _parameter,
    {String? urlFix}) async {
  var requestParams = "";
  String bodyResult = "";
  // var index = 0;
  var request = http.MultipartRequest("POST",
      Uri.parse(_getUrl(_method, urlFix: urlFix) + '?$requestParams'));
  // print("request ${_getUrl(_method, urlFix: urlFix)}?${requestParams}");
  // print("request2 ${request.url.toString()}");
  _parameter.data?.forEach((k, v) async {
    if (v is File) {
      File file = v;
      if (file.existsSync()) {
        String basename =
            file.path.split('/').last.toString().split(".").first.toString();

        // String basename = path.basename(
        //     pathh.substring(0, pathh.lastIndexOf(".") + 1) +
        //         getMimeType(pathh));
        // var stream = new http.ByteStream(Dele)
        // var stream = new http.ByteStream(DelegatingStream.typed(file.openRead()));
        var filestream = file.readAsBytes().asStream();
        var length = file.lengthSync();
        http.MultipartFile multipartFile = new http.MultipartFile(
            "$k", filestream, length,
            filename: basename);

        // var byet = file.readAsBytesSync();
        // final httpImage = http.MultipartFile.fromBytes('files.myimage', byet,
        //     contentType: MediaType.parse(mimeType), filename: 'myImage.png');
        request.files.add(multipartFile);
      }
    } else {
      request.fields[k] = '$v';
    }
  });
  // print("aklalallalal ");
  try {
    var response = await request.send();
    // .timeout(timeoutDuration!, onTimeout: () async {
    //   _handleResponseError(
    //       null, null, _method, _parameter, _onSuccessListener);
    //   return null;
    //   // return "true";
    // });

    // print("ses ${response}");

    bodyResult = await response.stream.bytesToString();
    // print(",asisiiii ${bodyResult}");
    // print("ses ${body}");
  } catch (exp) {
    // print("exxppa a${exp}");
    if (_onExceptionListener != null && exp is Exception) {
      _onExceptionListener!(exp);
    }
  }

  return bodyResult;
}