File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Delete file when the file downloaded. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Delete file when the file downloaded." Watch "Delete file when the file downloaded." New topic
Author

Delete file when the file downloaded.

vikas byn
Ranch Hand

Joined: Mar 18, 2011
Posts: 78
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

Joined: Aug 01, 2007
Posts: 485

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.


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
vikas byn
Ranch Hand

Joined: Mar 18, 2011
Posts: 78
is there any way, to identify end of stream?
Orton K Randy
Ranch Hand

Joined: Aug 12, 2011
Posts: 41

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.

Coderanch, best ever forum on the net. Hands down.
vikas byn
Ranch Hand

Joined: Mar 18, 2011
Posts: 78
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

Joined: Aug 01, 2007
Posts: 485

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

Joined: Mar 18, 2011
Posts: 78
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Delete file when the file downloaded.
 
Similar Threads
Browser gets refreshed after file download in Struts2
download content is outputting to my browser not creating a download file
downloading a file ok; also want to navigate to another page in the same action not sure how to
Struts 2 - FileDownload Problem.
download file in struts2