在Django中清理TemporaryFileUploadHandler处理的部分上传的文件 [英] Cleanup partly-uploaded files handled by TemporaryFileUploadHandler in Django

查看:793
本文介绍了在Django中清理TemporaryFileUploadHandler处理的部分上传的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TemporaryFileUploadHandler上传文件。如果用户正在上传大文件并取消上传,该文件将保留在我的临时目录中。



有没有办法捕获取消的上传(在文件已完全上传),以清理这些文件?



我可以想到的唯一选择是一个cron作业,它查看临时目录并删除在一段合理的时间内没有进行更新的文件。 >

解决方案

不确定是否有帮助,但您可以尝试连接到django请求信号:



request_finished - 当Django完成处理HTTP请求时发送。



got_request_exception - 当Django在处理传入的HTTP请求时遇到异常时,会发送此信号。 p>

我认为如果连接被中止,Django应该引发错误,所以第二个用法可能是一个解决方案。请让我知道它有帮助。


I am using the TemporaryFileUploadHandler to upload files. If a user is uploading a large file and cancels the upload, the file remains in my temporary directory.

Is there a way to trap a cancelled upload (connection reset before a file was fully uploaded) in order to cleanup these files?

The only alternative I can think of is a cron job which looks at the temp directory and deletes files which have not been updates in some reasonable amount of time.

解决方案

Not sure if it helps, but you may try to connect to django request signals:

request_finished - Sent when Django finishes processing an HTTP request.

got_request_exception - This signal is sent whenever Django encounters an exception while processing an incoming HTTP request.

I think Django should raise error if connection is aborted, so the usage of second one is probably a solution. Please let me know it it helps.

这篇关于在Django中清理TemporaryFileUploadHandler处理的部分上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆