Ask Your Question
0

What is the method for making an InputStreamResource accessible from postman?

asked 2023-02-10 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-02-15 19:00:00 +0000

qstack gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-02-10 11:00:00 +0000

Seen: 10 times

Last updated: Feb 15 '22