l'unica soluzione trovata per servire una immagine con spring 4 mvc senza impazzire...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping(value = "/image/{id}", method = RequestMethod.GET) | |
public void findImage(@PathVariable("id") String id, HttpServletResponse resp){ | |
final Foto anafoto = <find object> | |
resp.reset(); | |
resp.setContentType(MediaType.IMAGE_JPEG_VALUE); | |
resp.setContentLength(anafoto.getImage().length); | |
final BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(anafoto.getImageInBytes())); | |
try { | |
FileCopyUtils.copy(in, resp.getOutputStream()); | |
resp.flushBuffer(); | |
} catch (final IOException e) { | |
e.printStackTrace(); | |
} | |
} |