Bechir Landolsi
Bechir Landolsi

Reputation: 39

uploading multipart file to another server

I'm working on a spring boot / Angular 6 application, I want to upload files to a server, I followed this tutorial to upload a multipart file :" https://grokonez.com/spring-framework/spring-boot/angular-5-upload-get-multipartfile-to-from-spring-boot-server ". The upload of the file is on a folder in the application but now I want to upload the files to another server with URL; f.e : localhost:8081/uploads : it's another server, how can I do that?

Upvotes: 1

Views: 2209

Answers (1)

cricketmohit
cricketmohit

Reputation: 11

You should do this with spring rest template and construct the body as below

MultiValueMap<String, Object> body
  = new LinkedMultiValueMap<>();
body.add("files", getTestFile());
body.add("files", getTestFile());
body.add("files", getTestFile());

HttpEntity<MultiValueMap<String, Object>> requestEntity
  = new HttpEntity<>(body, headers);

String serverUrl = "http://localhost:8081/upload/";

RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate
  .postForEntity(serverUrl, requestEntity, String.class);

Upvotes: 1

Related Questions