Things to consider before coming to a solution:
- Will you be horizontally scaling your webapp (i.e. will you be running multiple servlet container instances).
- What kind of traffic are you expecting?
- How quickly does the image need to update (i.e. after a user changes their avatar, should they and all other users see the new avatar immediately).
For a webapp that is not horizontally scaled, you can use the file system as your image store. This is simple, understandable, and works.
For webapps that are horizontally scaled, you will need to store your images in a place that each servlet container can reach. This could be a database (I don't recommend this), S3 (I recommend this), or a content repository (I've never used one of these). One advantage of S3, is that it scales well. You can put it behind CloudFront (Amazon's CDN), or simply server off of S3 and keep the load off of your servers.
You also mention in your question that you can't server local resource from remote clients. This is correct, kind of... I'm guessing you're trying to use some URL like file://c:/.../image.jpg
. This won't work. What you need to do is map a handler to serve up the image. This might look something like
@RequestMapping(value = "/image/{name}.jpg", method = RequestMethod.GET)
public void image(@PathVariable("name") String name, HttpServletResponse response) {
// Read the image from the file system using java.io
// Write the image to the response output stream
// Even better use org.springframework.utils.FileCopyUtils
}