Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To make an InputStreamResource accessible from Postman, you will need to follow these steps:

  1. Create a controller method that returns the InputStreamResource. For example:
@GetMapping(value = "/download", produces = MediaType.APPLICATION_PDF_VALUE)
public ResponseEntity<InputStreamResource> download() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Disposition", "attachment; filename=example.pdf");

    ByteArrayInputStream bis = new ByteArrayInputStream(createPdf());
    InputStreamResource isr = new InputStreamResource(bis);

    return ResponseEntity.ok()
            .headers(headers)
            .contentType(MediaType.APPLICATION_PDF)
            .body(isr);
}

private byte[] createPdf() {
    // create the PDF byte array
}
  1. In Postman, make a GET request to the endpoint that returns the InputStreamResource. You should see the file download dialog box pop up.

  2. Click "Save" to save the file to your computer. You should now have access to the file.