code: private void writeMultipartDataRequest(HttpURLConnection connection, Request request, File file) {
          try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) {
              wr.writeBytes(NEWLINE);
              if (request != null && request.getJsonPayload() != null) {
                  wr.writeBytes(NEWLINE + "--" + BOUNDARY + NEWLINE);
                  wr.writeBytes("Content-Disposition: form-data; name=\"data\"");
                  wr.writeBytes(NEWLINE + NEWLINE);
                  wr.writeBytes(request.getJsonPayload().toString());
              }
              if (request != null && request.getMultipartData() != null) {
                  for (String param : request.getMultipartData().keySet()) {
                      wr.writeBytes(NEWLINE + "--" + BOUNDARY + NEWLINE);
                      wr.writeBytes("Content-Disposition: form-data; name=\"" + param + "\"");
                      wr.writeBytes(NEWLINE + NEWLINE);
                      wr.writeBytes(request.getMultipartData().get(param).toString());
                  }
              }
              if (file != null) {
                  if (!file.exists()) {
                      log.error("Unable to upload file with http call, as file can't be found: " + file.getName());
                  } else {
                      wr.writeBytes(NEWLINE + "--" + BOUNDARY + NEWLINE);
                      wr.writeBytes("Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"");
                      wr.writeBytes(NEWLINE);
                      wr.writeBytes("Content-Type: " + Files.probeContentType(file.toPath()));
                      wr.writeBytes(NEWLINE + NEWLINE);
                      byte[] bytes = Files.readAllBytes(file.toPath());
                      wr.write(bytes);
                  }
              }
              wr.writeBytes(NEWLINE + "--" + BOUNDARY + "--" + NEWLINE);
              wr.flush();
          } catch (IOException e) {
              log.error(e);
          }
      }
docs: Pushes request data to the open http connection
  
  @param connection - the open connection of the http call
  @param request    - the parameters to be passed to the endpoint for the service
  call
  @param file       - the file to upload with the request