• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Store Files on a Server

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic