views:

703

answers:

4

Best practice to specify external directory for storing images in Tomcat?

A: 

Best container independent answer is to put the location in JNDI.

For Tomcat you can put a class containing specific information in the Tomcat classpath. This is visible to the web applications.

Thorbjørn Ravn Andersen
A: 

I'll assume your image files do not need to be on the classpath. A good way of doing this is to designate a single directory outside of your web app root. Your application should then allow for configuration of this baseUrl property with absolute path values (as specified by the File class, i.e. like "C:/Dev/mypicsdir".

Keeping this dir outside your root and project allows you redeploy and update to a new version of your app without having to do anything with the stored files. If these images should be accessible from a browser, make a separate web app in Tomcat.

If possible limit this to a single directory, but you need to address that files saved are unique. One way is to control the file names yourself, or let users control the file name. In this last case you must also check if a file withe the chosen name already exists.

Paul
A: 

if linux you easily can map a symlink as /imagesext directory

Rodrigo Asensio
+1  A: 

The approach we use,

Get the base directory path using the System.getProperty (-D IMAGES_BASE_DIR="Your Base_Image_DIR")

next we can append/nest more directories based as required

Narayan