I have retrieved the image from Mongo DB using Spring Data and GridFs Template
so i don\'t know how to serve that retrieved input stream back to user .
I have used the spring boot and rest where this following code will work if you are using latest version of spring i.e.,Spring 4.1
@RequestMapping(value = "/image", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<InputStreamResource> getImage() {
GridFSDBFile gridFsFile = App.getImageResponse();
return ResponseEntity.ok()
.contentLength(gridFsFile.getLength())
.contentType(MediaType.parseMediaType(gridFsFile.getContentType()))
.body(new InputStreamResource(gridFsFile.getInputStream()));
}
I followed this post , Check out . Spring MVC: How to return image in @ResponseBody?