I wrote a simple SpringMVC app and host on a Paas. I have created a table in Mysql and a column is the Blob. I can upload files through the Mysql admin. Right now, my server can serve html file or javascript files correctly in browser. However, when I serve a jpg file in http://myserver.com/File/ad.jpg, my browser showed a small icon and if I save it, the Windows Image software shows that the image is damaged.
Here are some of the code:
@RequestMapping(value="/File/**", //{name:.+}",
method = RequestMethod.GET)
public @ResponseBody void getContent(
// @PathVariable("name") String name,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
String name = request.getPathInfo();
....
IOUtils.copy(blob.getBinaryStream(), out);
I found that getServletContext() returns null, so I wasn't able to get contentType, so I saved contentType in Mysql as image/jpeg for the ad.jpg. I set the disposition to be inline. What else should I do to serve a jpg?