文件下载后删除文件
我必须实现一个功能 - 当用户下载文件完成时删除服务器上的文件。我们不想再将该文件存储在服务器上。
我正在使用 struts2 在 tomcat 服务器上下载文件。如何判断文件下载是否完成。截至目前,我可以成功下载文件,但是什么时候应该删除该文件?
操作类中的代码:
contentType=new MimetypesFileTypeMap().getContentType(fileName);
File f=new File("/home/vikasbarsaiyan/downloadables/"+fileName);
inputStream = new FileInputStream(f);
struts.xml
<action name="downloadFile" class="mypack.action.FileTransferAction"
method="downloadFile">
<result name="success" type="stream">
<param name="contentType">${contentType}</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">filename="${fileName}"</param>
<param name="bufferSize">4096</param>
</result>
</action>
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:
contentType=new MimetypesFileTypeMap().getContentType(fileName);
File f=new File("/home/vikasbarsaiyan/downloadables/"+fileName);
inputStream = new FileInputStream(f);
struts.xml
<action name="downloadFile" class="mypack.action.FileTransferAction"
method="downloadFile">
<result name="success" type="stream">
<param name="contentType">${contentType}</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">filename="${fileName}"</param>
<param name="bufferSize">4096</param>
</result>
</action>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试了别的东西。我创建了一个类并扩展了 java.io.FileInputStream。这样:
并在动作类中使用。示例:
这是问题的解决方案。
我测试了这个并且成功了。
I tried something else. I created a class and extends java.io.FileInputStream. This way:
and using in action class. Example:
this was problem solution.
I tested this and success.
尝试使用 java script.in OnDownloadComplete() 事件在客户端提交。
服务器上的脚本接收提交的文件名,查找并删除它。
try a submit at client end using java script.in OnDownloadComplete() event.
Script at server to receive the submitted file name, find and delete it.