0

A micro-service is providing an api(get request) to download a file which is having a return type as void. It is populating HttpServletResponse but not returning it. How can I get the data from such api?

@GetMapping(value="/download/{id}")
    public void download(@PathVariable(value = "id") String id, HttpServletResponse response) {
       FileDTO file = downloadFile(id, response);
       response.setContentType("text/html");
       ....
       ....
    }

How can we get the html/text data from the above sample snippet? (Assume all required parameters are set.)

TechGuy
  • 1
  • 1
  • Juding from this [question](https://stackoverflow.com/questions/5673260/downloading-a-file-from-spring-controllers) that looks like a valid way to do this. How does the response you receive look like? – second Mar 23 '20 at 14:15
  • Write the data of the file to be downloaded directly into the HttpServletRespone. Perhaps this will help you https://o7planning.org/en/11765/spring-boot-file-download-example. – Devilluminati Mar 23 '20 at 14:35
  • @Devilluminati: As its not his api he won't be able to change it. Assuming that its properly implemented I don't see any issue why the file should not be contained in the response. So it should be readable by the client as usual. – second Mar 23 '20 at 14:45
  • @All thanks for your time. Found the solution. When you set file to body then you can retrieve contents using response.body() . – TechGuy Mar 24 '20 at 08:20

0 Answers0