I am trying to return the image to spring-boot (1.2.2)
How to set the content type? Not the following ones work for me (this means that the response headers do not contain the "content-type" header at all):
@RequestMapping(value = "/files2/{file_name:.+}", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> getFile2(final HttpServletResponse response) throws IOException { InputStream is = //someInputStream... org.apache.commons.io.IOUtils.copy(is, response.getOutputStream()); response.setContentType("image/jpeg"); InputStreamResource inputStreamR = new InputStreamResource(is); return new ResponseEntity<>(inputStreamR, HttpStatus.OK); } @RequestMapping(value = "/files3/{file_name:.+}", method = RequestMethod.GET) public HttpEntity<byte[]> getFile3() throws IOException { InputStream is = //someInputStream... HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_JPEG); return new HttpEntity<>(IOUtils.toByteArray(is), headers); }
source share