• Post Reply Bookmark Topic Watch Topic
  • New Topic

Where to store uploaded pictures?  RSS feed

 
Denis Labaffe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I'm learning servlets. I wrote one that uploads pictures to an "upload" directory in the context of my application, ie TOMCAT_ROOT/webapps/context/upload.
Tomcat displays my pictures with a simple A HREF="/context/upload/picture.jpg"

Old problem was: Everytime I upgrade my servlet, the upload directory is destroyed and its content is lost.

So I moved the upload directory outside of my application. I tried first to put it in the /webapps directory, then in the tomcat's root directory, but Tomcat couldn't find the pictures (404 errors). I think it's kind of normal, these directories having special meanings?

So where should I put this directory, so that I don't have the risk of losing its contents whenever I upgrade my application, but so that Tomcat is able to deliver pictures without using another servlet to read it?
And... Is it considered bad to write outside of the application directory? I'm not comfortable with this idea...

Thanks for shedding some light!
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you investigated why the directory gets deleted? Are you using a war file?

If the images are somehow connected to this particular web app, then a directory within it seems appropriate. Either inside of WEB-INF -if the images should not be publicly accessible- or at the context top level if they're supposed to be accessible.
 
Balaji kkk
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can store your images to where your folder is place in the web apps inside web apps definitely you have folder so create a new folder there and store your images
 
Denis Labaffe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answers.

Ulf Dittmer wrote:Have you investigated why the directory gets deleted? Are you using a war file?

You're right, I'm may be not focusing at the real problem!

YES, I'm using a WAR file. I copy it to Tomcat's webapps directory and use Tomcat's manager to undeploy/deploy my application.

What would be the correct way to deploy my application without erasing uploaded pictures?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never store transient data such as uploaded files within the web app. It makes it hard to deploy and update. Rather, I have a separate folder that I serve the files from using a simple streaming servlet.

On occasion, I'll have a separate web context set up to store the files so that they can be directly accessed via URL, but they're basically their own web app that never needs to be redeployed.
 
Vinod K Singh
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uploaded images should be stored out of the Tomcat, say at '/opt/some_location'. Then create a symbolic link to this storage location from where these are supposed to be served by the application deployed on Tomcat.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!