On my website; users can upload their pictures. I am using tomcat with apache , hibernate, jpa.
I would prefer to keep these images at some location like /var/ImagesUploaded on my ubuntu box. Using Java I can refer these files in directory /var/ImagesUploaded using java.io but how will I show these images on HTML pages to user? On HTML files we need tags like <img src=''> and this src is relative to the webapp. So, is it that I have to keep the user uploaded images inside my webapp ONLY! Or is there a better solution?
How about reading the images on your application, and then serve them to your user as a base64 encoded stream? That way, you don’t have to expose your image directory to the web, and can effectively prevent it from being crawled by bots.
InputStreaminside your application using java.ioencodeBase64URLSafeString(IOUtils.toByteArray(yourImageAsInputStream);<img src="data:image/jpeg;base64,encodedString">This post on SO might be useful as well.