Skip to content

Instantly share code, notes, and snippets.

@varaprasadh
Created March 11, 2023 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varaprasadh/2c46797ec5ed977d70cbcd53fec61eac to your computer and use it in GitHub Desktop.
Save varaprasadh/2c46797ec5ed977d70cbcd53fec61eac to your computer and use it in GitHub Desktop.
File file = new ClassPathResource("logo.png").getFile();
HTTPRequestMultipartBody multipartBody = new HTTPRequestMultipartBody.Builder()
.addPart("name", request.getName())
.addPart("file", request.getFile(), request.getFile().getContentType(), request.getFile().getOriginalFilename())
.addPart("file1", file, null , request.getFile().getOriginalFilename())
.build();
HttpRequest httpRequest = HttpRequest.newBuilder()
.header("Content-Type",multipartBody.getContentType())
.uri(new URI("https://webhook.site/7b944491-9fa3-4f2a-92ea-9231d532e86f"))
.POST(HttpRequest.BodyPublishers.ofByteArray(multipartBody.getBody()))
.build();
HttpResponse<String> response = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment