HttpRequestHandler { public static HttpResponse sendMultipartRequest(URI request, Map<String, File> files, Map<String, String> textBody) throws IOException { HttpClient httpClient = HttpClients.createDefault(); HttpPost uploadFile = new HttpPost(request); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); if (textBody != null) { for (Map.Entry<String, String> entry : textBody.entrySet()) { builder.addTextBody(entry.getKey(), entry.getValue(), ContentType.TEXT_PLAIN); } } if (files != null) { for (Map.Entry<String, File> entry : files.entrySet()) { InputStream inputStream = new FileInputStream(entry.getValue()); builder.addBinaryBody( entry.getKey(), inputStream, ContentType.APPLICATION_OCTET_STREAM, entry.getValue().getName() ); } } HttpEntity multipart = builder.build(); uploadFile.setEntity(multipart); return httpClient.execute(uploadFile); }  static HttpResponse sendGetRequest(URI request); static HttpResponse sendPostRequest(URI request, ArrayList<NameValuePair> parameters); static HttpResponse sendMultipartRequest(URI request, Map<String, File> files, Map<String, String>
            textBody); static String printResponse(HttpResponse response); static void saveResponseToFile(HttpResponse response, File destinationFile);  }
@Test public void testSendMultipartRequest() { String request = "http: Map<String, File> files = new HashMap<>(); files.put("testFile", new File("/home/deshani/Documents/uploaded")); Map<String, String> textBody = new HashMap<>(); textBody.put("testText", "test"); try { HttpRequestHandler.sendMultipartRequest(new URI(request), files, textBody); } catch (IOException | URISyntaxException e) { assertTrue(false); } }