File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to view uploaded files in Tomcat till server is refreshed

 
Akash Singla
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am building an application wherein the user would have an option to upload files (can be documents or images) and once the files are uploaded the user should be able to download it.

I am using Apache Tomcat 6.0 and JDK1.6.
Every thing seems to be OK for the File Upload part but I have some questions in my mind for the File Download Part.

Approach 1:
Initially I tried to use the BLOB feature of the mysql Database to save the file as a Binary stream in the DB. However after googling it out I found out that there are serious performance issues with BLOB (The file size can be anywhere from 1 KB to 20 MB). Thus we have ruled out this approach.

Approach 2:
We decided to save the file path in the DB and save the file to the File System.

For this, Initially we stored the files under the Root directory of the application but the Tomcat could not recognize the files until it was refreshed/restarted.
This can’t be accepted for the realtime environment.
One fix we found out for this was to create a new file directory under the web-apps folder of tomcat outside the root directory of the application and save the files in this directory. To make this work we added a new context to the tomcat configuration.

Please suggest if this is the best approach to follow.

Thanks
Akash Singla
http://www.TheDaedals.com
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do similar things often.

I don't store the files anywhere within the web app. That makes it hard to update and redeploy the web app because now it's a mix of the app and its data files. What a mess.

Rather, I store the files elsewhere on the file system. Then I allow access to them through a servlet that reads the files and streams them as the response.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As there is nothing Tomcat-specific about this, it's been moved to the Servlets forum.
 
Akash Singla
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear, we'll try it and let you know

Bear Bibeault wrote:I do similar things often.

I don't store the files anywhere within the web app. That makes it hard to update and redeploy the web app because now it's a mix of the app and its data files. What a mess.

Rather, I store the files elsewhere on the file system. Then I allow access to them through a servlet that reads the files and streams them as the response.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got burnt very badly when I inherited a project that was storing images inside the WAR directory. First software upgrade, and "BAM!" All the images are gone.

Besides, you can't upload files into a WAR unless it's an exploded WAR. And exploded WARs actually aren't part of the J2EE architecture. They're a "feature" of some, but not all J2EE appservers. In fact, while some versions of Tomcat would automatically explode WAR files, some don't appear to, and it's a configurable option on most of the recent ones, I think.

It can be a problem, however, using an external data directory, since that codes a dependency on your server's filesystem into the app. A good way of getting around that is to define the directory path as a web.xml resource and look it up via JNDI. In Tomcat, you can override the default value in web.xml without actually having to modify web.xml itself. Although even that's better than having to change source code and recompile.

Blob avoidance is one of those Urban Legends. I wouldn't just assume that because someone says so that they're always going to be a bad solution, but rather do an app-specific case study. Obviously, as always, abstracting your storage mechanism will help in switching mechanisms once you find which way you want to go. And change that mechanism later, if it proves profitable.

Oracle 11 was claiming that database accesses were faster than file accesses, for example. YMMV.

One thing I do know from my own project. It can be a real pain when the images are in the filesystem when you're using the database on a separate test machine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic