title: How to return image in Spring REST to browser
body: <p>I need to return image in my Spring controller. 
  I try answer in this <a href="https://stackoverflow.com/questions/5690228/spring-mvc-how-to-return-image-in-responsebody">Spring MVC: How to return image in @ResponseBody?</a> but it's not working</p>
  
  <p>my code is like this</p>
  
  <pre><code>@RequestMapping(value = "cabang/photo", method = RequestMethod.GET)
  @ResponseBody
  public ResponseEntity&lt;byte[]&gt; getPhoto() throws IOException {
  
       File imgPath = new File("D:\\test.jpg");
  
      byte[] image = Files.readAllBytes(imgPath.toPath());
      HttpHeaders headers = new HttpHeaders();
      headers.setContentType(MediaType.IMAGE_JPEG);
      headers.setContentLength(image.length);
      return new ResponseEntity&lt;&gt;(image, headers, HttpStatus.OK);
  }
  </code></pre>
  
  <p>but when I access it in browser, it doesn't show anything (just no picture icon). But if I read the image byte array, it is not empty.
  Do I miss anything in my code? </p>