I am wondering where should i save files uploaded by user in my application. Right now i am saving them right into webapps/images/uploads(webapps folder is mapped as resource folder via mvc-resource) folder and they are instantly available to display after upload. But i am not sure if this is the right thing to do? how will redeployment of application affect the files already stored there? won't it complicate back ups of application? so basically where should i store them on server? and is this affected somehow by using local(windows) or remote(linux) server Thanks
1 Answer
I will use a separate directory outside the webapp directory of the application server. In case of update of the application, this seems more appropriate. Just be careful how you save the file name in the database (it's better to save the file without any path, in case of changes).
5 Comments
Schyzotrop
exactly this is what i am thinking about, but how can i make this directory acessible for public? how to serve content from it?
Schyzotrop
forgot to add i am using tomcat 6
Kartoch
You can place a directory in webapp. The content will be available as a static resources. You can also write a servlet which will return the file from the upload directory with appropriate content-type.
Fixus
@Kartoch - I want to ask you one question. You mean in tomcat/webapp ? or webapp in the project folder ?
Fixus
@Kartoch - how can I map my app on a directory outside webapp ? I`ve done <resources mapping="/uploads/**" location="D:/uploads/" /> but it doesn not work :(