2

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?

Splash
  • 1,288
  • 2
  • 18
  • 36

1 Answers1

1

I finally found that the original code has nothing wrong. The original Mysql admin web page uploaded the blob incorrectly. After I found the Paas has a secret new admin page and that can upload a correct blob with an binary option. I still appreciate all the replies in comments.

Splash
  • 1,288
  • 2
  • 18
  • 36