Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Download file from server, then delete it from server?  RSS feed

 
joseph corner
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am making an "archive" facility for a jsp discussion forum. On the server, I want to write a thread to an html file, put it in a folder with image resources, zip it all up and offer the zip for download.
I *think* I can manage all of that, but I'm not sure how to go about deleting the zip on the server afterwards. How can i be sure that the download is finished?
Any suggestions as to how I might approach this?
thanks,
J
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most sites I know of will give a link to the file and say it is available for 30 minutes then it gets deleted that way you do not have to worry about if it was fully downloaded and it will not clog up your server space.
 
joseph corner
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, sounds good. Would you start a timer thread to time the 30 minutes, or is there is a more resource efficient way to do that?
Thanks,
J
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might implement a SessionListener which deletes the file when the user session expires.
May not be exactly 30 minutes, but 30 minutes (if you haven't changed the session timeout most servers use that as a default) after the user leaves the site (or when he logs out) the file will go.
 
joseph corner
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
I'll look into that.
J
 
joseph corner
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well,
when I use a session listener, I try to retrieve session-specific attributes (the paths of the files to delete) in the sessionDestroyed() method.
However, the session is already invalidated by that point, and getAttribute gives an exception.
How else could I retrieve session specific info. at the point of the session ending?
Thanks,
J
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only way is to wrap all you need in your Listener and store the whole in the session instead of (or next to, but I don't like the idea of storing multiple copies of things even if only references) the separate parts.
That way you will have all the data still available even though you can't retrieve them from the session anymore.
 
joseph corner
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeroen,
Thanks for the answer, but I'm not clear what you mean by wrapping everything I need in the listener.
Cheers,
J
 
joseph corner
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by the way, another approach I've tried is to put the files to be deleted in folder named after the session ID. Then, on sessionDestroy(), I get the session ID and delete any folders with that name.
Which is good in theory, but in practice the deletion of the folder isn't happening (yet).
J
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simple. You have one object implementing the HttpSessionBindingListener I guess?
Make that object contain references to everything it needs to clean up the session, so that it doesn't need to access anything from the session (which will be gone by then).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!