Cleanup partly-uploaded files handled by TemporaryFileUploadHandler in Django

妖精的绣舞 提交于 2019-12-24 03:14:47

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8670982/cleanup-partly-uploaded-files-handled-by-temporaryfileuploadhandler-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!