0

So I have a method

@GetMapping(
            value = "/download/{fileId}",
            produces = { MediaType.APPLICATION_OCTET_STREAM_VALUE }
    )
    public ResponseEntity<InputStreamResource> download(@Valid @PathVariable(value = "fileId") String fileId) {
        InputStreamResource file = new InputStreamResource(service.download(fileId));

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(new MediaType(MediaType.APPLICATION_OCTET_STREAM, Charset.forName("UTF-8")));
        headers.setContentDispositionFormData("attachment", fileId+".doc");
        headers.add("Content-Transfer-Encoding", "binary");

        return ResponseEntity.ok()
                .headers(headers)
                .body(file);
    }

and when I hit the API from postman, it returns : enter image description here

How can I make the output readable and downloadable from postman?

  • By the way, you should read this: https://stackoverflow.com/questions/66637127/is-the-charset-parameter-allowed-on-application-octet-stream-mime-type – tgdavies Mar 30 '23 at 22:53
  • And this may help: https://stackoverflow.com/questions/38975718/how-to-download-excel-xls-file-from-api-in-postman – tgdavies Mar 30 '23 at 22:54

0 Answers0