<pre lang="Java">var file = new File(tempDirectory + File.separator + myFile); var multipartBodyBuilder = new MultipartBodyBuilder(); multipartBodyBuilder.part("ticket", ticket, MediaType.TEXT_PLAIN); multipartBodyBuilder.part("file", new FileSystemResource(filePath), MediaType.APPLICATION_PDF).filename(fileName); var mimeMultipartData = multipartBodyBuilder.build(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); WebClient webclient = client.getConnectionProvider().createWebClientBuilder(url, true, headers) .build(); return webclient.post().body(BodyInserters.fromMultipartData(builder.build())).exchangeToMono(response -> { if (response.statusCode().isError()) { return response.createException().flatMap(Mono::error); } return response.bodyToMono(String.class); }).block().trim(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)