Tomcat – Apache Tomcat directory access, restricted and accessible only by web application

.htaccessapache-2.2tomcat

I have a Grails app. I want to move out all the images users upload to a directory outside of my web-app directory, somewhere else on the disk. Then I want to allow my application to serve them on pages but users can't access the directory. I know one way if to use an ImageController that reads the image and streams it to the view, but that has some trades-off such as caching. I was wondering if there is a way to allow apache to serve images from a local directory outside the web-app and restrict it to the app only.

Best Answer

I tried this, and it worked. But It also allows the client to access it since it only maps it. But again I appreciate if anyone can elaborate more and offer another solution that provides more control over how web app and users can access this area.

basically added this in Tomcat /conf/server.xml inside <Host> tag:

<Context docBase="/path/to/images" path="/images" />

Found out that someone answered something like what I needed here : Simplest way to serve static data