title: 406 on returned image
body: <p>I have a Spring Boot app that acts as an image server.  I am getting a 406 when I try to return the mongodb stored image. </p>
  
  <p>here is the error that I get:</p>
  
  <blockquote>
    <p>Method [error] returned [&lt;406 Not Acceptable,{timestamp=Tue Jul 28
    16:50:57 MDT 2015, status=406, error=Not Acceptable,
    exception=org.springframework.web.HttpMediaTypeNotAcceptableException,
    message=Could not find acceptable representation,
    path=/images/1438123819971_10420419_10204541009433090_4380886302080092329_n.jpg},{}>]</p>
  </blockquote>
  
  <p>and here is the GET method:</p>
  
  <pre><code>@RequestMapping(value = "images/{filename}", method = RequestMethod.GET)
  @ResponseBody
  public ResponseEntity getSizedImage(@PathVariable String filename, @RequestParam int width, @RequestParam int height) throws Exception {
  
          GridFSDBFile savedFile = mongoFileService.getStore(filename);
          if (savedFile != null) {
              BufferedImage image = ImageIO.read(savedFile.getInputStream());
              image = resize(image, Method.SPEED, width, height, Scalr.OP_ANTIALIAS);
  
              LOGGER.info("Returning Filename " + savedFile.getFilename() + " sized to " + width + " X " + height);
              return ResponseEntity.ok().contentLength(savedFile.getLength())
                              .contentType(MediaType.parseMediaType(MediaType.IMAGE_JPEG_VALUE)).body(image);
          } else {
              LOGGER.error("Error retrieving file " + filename );
              return ResponseEntity.status( HttpStatus.INTERNAL_SERVER_ERROR )
                              .contentType( MediaType.TEXT_PLAIN).body(MISSING_IMAGE_PATH );
          }
      }
  </code></pre>
  
  <p>Any ideas why this image won't return in my ResponseBody?</p>
  
  <p>Also, I noticed that the file extension doesn't appear as part of the filename parameter.  I can manipulate it in the debugger, appending a ".jpg" and the file is retrieved and resized.</p>
  
  <p><strong>UPDATE</strong>
  Here was the solution that worked for me, based on feedback:</p>
  
  <pre><code>@RequestMapping(value = "images/{filename}", method = RequestMethod.GET)
      @ResponseBody
      public ResponseEntity getPatientSizedImage(@RequestParam String filename, @PathVariable int width, @PathVariable int height) throws Exception {
  
          GridFSDBFile savedFile = mongoFileService.getStore( filename );
          BufferedImage image = ImageIO.read( savedFile.getInputStream() );
          image = resize( image, Method.SPEED, width, height, Scalr.OP_ANTIALIAS );
  
          LOGGER.info( "Returning Filename " + savedFile.getFilename() + " sized to " + width + " X " + height );
          return ResponseEntity.ok().contentLength( savedFile.getLength() )
                  .contentType( MediaType.parseMediaType( MediaType.IMAGE_JPEG_VALUE ) ).body( image );
      }
  </code></pre>