0

I want to send the file via API request, below is my code:

MultiValueMap<String, Object> body  = new LinkedMultiValueMap<>();
FileSystemResource file = new FileSystemResource("my_file_path");
body.add("dagFile", file);

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

RestTemplate restTemplate = restTemplate();

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

Here i am providing the file path i.e file should be there present in the disk, is there any way via which i can create file in-memory and process my request : Sudo Code :

    String filecontent = "12345";
    MultiValueMap<String, Object> body  = new LinkedMultiValueMap<>();
    FileSystemResource file = new FileSystemResource(filecontent); // passing content as string
    body.add("dagFile", file);
Marcin_S
  • 529
  • 3
  • 14

0 Answers0