This question may be stupid, but I don't really see how to resolve it : let's say that in my application, I have a user. This user edit his profile, and need to edit his avatar.
Where should I store the avatar file?
first of all I was saving all the files in src\main\webapp\resources, but each time I redeploy that folder empties.
So I decided to place in another location : c:\wwwdir\resources, but I can't link local resources from remote pages, so I was not able to display any avatar .
Any idea? advise? link?
Things to consider before coming to a solution:
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With