aspose file tools*
The moose likes Java in General and the fly likes Store Files on a Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Store Files on a Server" Watch "Store Files on a Server" New topic
Author

Store Files on a Server

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I am using the Tomcat 5.0.27 web container. I have always store things into the database. Now, I am told to store files (uploaded files) on the server. And, when clients want the files later on, clients can download them.

Because I have not yet had this concept, I need help and explanation.

1. How to store files on a server?
2. Where on the server that files can be stored?
3. How to let clients download files when they are asked to be viewed?
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Originally posted by JiaPei Jen:
I am using the Tomcat 5.0.27 web container. I have always store things into the database. Now, I am told to store files (uploaded files) on the server. And, when clients want the files later on, clients can download them.

Because I have not yet had this concept, I need help and explanation.

1. How to store files on a server?
2. Where on the server that files can be stored?
3. How to let clients download files when they are asked to be viewed?



1. I'm not sure if you're asking just where you're allowed to store files, or if you also need to know how to get them up there. There are some nice high-level ways of uploading files in Java, and if you Google around with the following search terms, I'm sure you'll find what you need: java fileupload tutorial
Here are some:
The Apache Commons FileUpload package: http://jakarta.apache.org/commons/fileupload/
FileUpload with HttpClient: http://www.theserverside.com/articles/article.tss?l=HttpClient_FileUpload

2. As for where you can store the files on the server...well, you can kind of store them anywhere you can reach them from your web app's code. To make it easy, you could just make another directory under your web app's root directory. If you have any images or some sort of auxiliary files, you're probably storing them in an images folder, right? Just make another directory like that.

3. When a user wants to browse the uploaded files, go look for all the files in that directory and then return that list of files to the user. When they choose a file they want to download, then in your back-end code go retrieve that file and push it down to them. This way you're not blatantly advertising the location of these files.
 
jQuery in Action, 2nd edition
 
subject: Store Files on a Server