Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Delete file when the file downloaded.

 
vikas byn
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to implement a functionality - delete the file on server when user download file is complete. we do not want store that file on server anymore.

I m using struts2 for downloading file on tomcat server. How can i identify file downloading is complete. as of now, i can download file successfully but when the file should be deleted?

code in action class:


struts.xml
-----------------
 
Mohana Rao Sv
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
write a custom interceptor to delete the file and make sure that this will be executed only after successful completion of downloading file. Ask me if you have any doubts.
 
vikas byn
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any way, to identify end of stream?
 
Orton K Randy
Ranch Hand
Posts: 41
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mind using AJAX? Here's a comprehensive solution that you can relate your question to. Here's a bit more insight into the same. Or even this could be of some help.

Not into AJAX? The following code snippet in your servlet is supposed to let you know if the download has completed.

Supposedly, the file download will be completed as soon as the while loop is exited.
Hope that helps.
 
vikas byn
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohana Rao wrote:write a custom interceptor to delete the file and make sure that this will be executed only after successful completion of downloading file. Ask me if you have any doubts.


actually I am not sure about Interceptor is the good idea. Intercept just intercept the Action execution. It will not have information when the end of stream occurred. Browser transfer files over http So i think there is something different kind of solution.
 
Mohana Rao Sv
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interceptors are objects that dynamically intercept Action invocations. They provide the developer with the opportunity to define code that can be executed before and/or after the execution of an action. They also have the ability to prevent an action from executing. Interceptors provide developers a way to encapulate common functionality in a re-usable form that can be applied to one or more Actions. So, write an interceptor which is responsible for deleting the file. It(Interceptors) will not be called until and unless you result execution is successful.
 
vikas byn
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohana Rao wrote: Interceptors are objects that dynamically intercept Action invocations. They provide the developer with the opportunity to define code that can be executed before and/or after the execution of an action. They also have the ability to prevent an action from executing. Interceptors provide developers a way to encapulate common functionality in a re-usable form that can be applied to one or more Actions. So, write an interceptor which is responsible for deleting the file. It(Interceptors) will not be called until and unless you result execution is successful.


thanks for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic