To make an InputStreamResource accessible from Postman, you will need to follow these steps:
@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
}
In Postman, make a GET request to the endpoint that returns the InputStreamResource. You should see the file download dialog box pop up.
Click "Save" to save the file to your computer. You should now have access to the file.
Asked: 2023-02-10 11:00:00 +0000
Seen: 11 times
Last updated: Feb 15 '22