Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

File Uploads - how to make uploaded file available for download  RSS feed

 
Annemarie McKeown
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP file which manages file uploads and sends them to some server.
I need to then use the location of that file on the server and provide a link to download the uploaded files....How do I do this?
Does anyone know?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two ways to do this, but either way it would be best to remember the file so that you are aware of the files that have been uploaded - like storing the filename in the database.
The easiest way is to save the uploaded file directly to the web-root, so that you can provide a link straight to the file.
A better way that involves a bit more work is to have an intermediate Servlet for the download. The user requests the file throught the Servlet either by name or id eg /DownloadServlet?file=file123.bin, then the Servlet finds the file from the storred information and pipes the file back through the binary stream obtained from the HTTP response.
Slightly more work is to hide the fact that they are not downloading the file directly, but hide it in the URL eg /download/file123.bin where download is a servlet and not a directory.
The advantage of using a Servlet is that it gives you greater programatic control over the download. You can check permissions, hide the real location of the files, and keep track of who dowloaded what and when.
Dave
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!