KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I seem to have run into an interesting problem where the browser happily displays an image generated by my Spring MVC web application as long as the URL to my controller is set as SRC of an IMG tag, but displays binary data when navigated directly to the URL. My Spring MVC Controller generates some BufferedImage (thumbnail), converts it to byte[] and returns it directly into the response body using the @ResponseBody annotation on the controller method. I have registered a org.springframework.http.converter.ByteArrayHttpMessageConverter message converter with the AnnotationMethodHandlerAdapter and even set its supportedMediaTypes property to image/jpeg , which wasn't really helping, so I am setting the Content-Type header on the response manually in the controller method. <img src="/images/thumbnail?id=1234" /> works fine and displays the image, however navigating directly to the SRC of the image (or right-clicking the image and choosing View Image) ends up displaying the raw data of the image. Response headers, according to Firebug, received from a request to such URL ( http://localhost:8888/images/thumbnail?id=F0snPkvwhtDbl8eutbuq ) are: HTTP/1.1 200 OK Expires: Wed, 21 Dec 2011 12:39:07 GMT Cache-Control: max-age=2592000 Content-Type: image/jpeg Content-Length: 6998 Server: Jetty(6.1.10) One last word: in Firebug, clicking on the Response tab displays the image :-) What am I missing out? I thought the browser receives the content-type and content-length headers, knows to expect jpeg image, receives raw data for the jpeg, then displays jpeg in the empty browser tab. Somehow FF, and Chrome are displaying raw image data received. Code I am using: @RequestMapping(value = "thumbnail", method = { RequestMethod.GET }) @ResponseBody public byte[] getImageThumbna
Tags (comma-separated)
Save Edits
Cancel