Alain BUFERNE
Alain BUFERNE

Reputation: 2071

Tomcat SymLink with DocBase

I need to upload documents outside of my webapp with the possibility of serving them after to a browser. So after looking at many posts I decided to create a symlink. I have a problem because I already have a context in tomcat5/Catalina/loclahost/myApp.xml. I added to it the attribute allowlinking = true and override = true. But I can't access my uploaded documents with my browser. I think the two redirections don't work together, but I have no idea how to do it in any other way. So any idea would be welcomed

Upvotes: 0

Views: 375

Answers (1)

Christopher Schultz
Christopher Schultz

Reputation: 20882

If you need a safe place to upload files to your webapp, you will need to put them completely outside of any webapp's docbase -- and that includes using symlinks to "mount" them into your URL space by leveraging the DefaultServlet to serve those bits for you. To do otherwise puts you at risk of having Tomcat delete all your uploaded files when the webapp is undeployed.

If you don't have to the option to upgrade to Tomcat 7.0 (which I highly recommend), then I suggest that you write your own servlet, map it to /myapp/files/*, and have that servlet read the files from the upload directory and serve the bits to the client. There are ways to make the DefaultServlet do this for you (rather than essentially duplicating its full feature set in your own servlet), but it doesn't always work well and might not work at all in older versions of Tomcat because DefaultServlet assumes that it is mapped to "/" and not something like "/files".

Upvotes: 1

Related Questions