0

I need to read blob from database and show image as output is there any way I can do it? I can save image as blob in database but could not fetch it from database.

@RequestMapping(value = "/getlogo", method = { RequestMethod.GET,RequestMethod.POST })
    public @ResponseBody BufferedImage getlogo(HttpSession session, @RequestBody ApplicationVO apo) throws IOException {
        byte[] result=null ;
      String appid=apo.getAppid();
        logger.info("Application id :"+appid);
      result=appService.getlogo(appid);
      BufferedImage image=ImageIO.read(new ByteArrayInputStream(result));
      return image;
    }

this gives me error as : org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError)

Thank you

Aniket G
  • 47
  • 5
  • You don't need a `BufferedImage` there. That's a Java object, not something you display in the browser. Return the bytes themselves with a suitable contenttype. – Kayaman Feb 19 '18 at 09:18
  • Seems like this can be helpful https://stackoverflow.com/questions/5690228/spring-mvc-how-to-return-image-in-responsebody – ikos23 Feb 19 '18 at 09:18

0 Answers0