title: Request for Reactive Server response with image content type Sample
body: <p>I'm starting a new project and adopting spring webflux as reactive rest framework. I have a use case that return captcha image at the backend. I have a sample code as below which generate captcha image and return with spring framework but now I have no idea how to return the image with reactive way. </p>
  
  <p>This is my use case in Spring MVC way:</p>
  
  <pre><code>@RequestMapping(value="/captcha/{id:.+}", produces = MediaType.IMAGE_JPEG_VALUE)
  public @ResponseBody byte[] captcha(@PathVariable("id") String captchaId,  HttpServletResponse res) throws Exception{
  
        try{
           byte [] captchaImg = (byte[])cacheService.getValue(captchaId,    AuthConstants.CACHE_CAPTCHA_IMG_KEY);
  
           return captchaImg;
        }catch(Exception e){
          res.setStatus(HttpStatus.NOT_FOUND.value());
          return null;
        }
  }
  </code></pre>
  
  <p>In reactive way which is failure code as below:</p>
  
  <pre><code>public Mono&lt;ServerResponse&gt; captchaImage(ServerRequest request) {
  
          return Mono.just(request.pathVariable("id"))
                  .flatMap(id-&gt;cacheService.getValue(id, AuthConstant.CACHE_CAPTCHA_IMG_KEY))
                  .flatMap(captchaImage-&gt; {
                      System.out.println("img:"+captchaImage);
                      return ServerResponse
                              .ok()
                              .contentType(MediaType.IMAGE_JPEG)
                              .body(BodyInserters.fromObject(captchaImage));
                  });
  
      }
  </code></pre>
  
  <p>This code is failure and I can't find any information to get idea how to do it.</p>
  
  <p>I need your help. Appreciate that you can provide some snippet code.</p>
  
  <p>Thanks</p>