在Django中,有什么方法可以在多个请求中访问上传的文件?
我正在构建一个应用程序,用户可以上传他们的文件并转到付款页面。付款完成后,我想将用户上传的文件存储在数据库中。如果用户未完成付款,则我不想保存服务器或数据库上的文件。
有什么办法吗?
I am building an application where users can upload their files and go to the payment page. After payment completion, I want to store the files uploaded by the user in the database. If the user does not complete the payment, then I do not want to save the files on the server or database.
Is there any way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里打开两件事。
首先,不建议将文件存储在数据库中。最好使用存储或直接使用服务器的文件系统。
其次,通常根据您的策略(在服务器的文件系统,数据库或第三方存储)上上传和保存文件,然后如果用户未进行付款,将进行清理。您需要定义进行清理的条件,无论是因为用户上传文件并且在一定时间段内一直不活动,还是因为他们单击了特定的按钮,还是两者的组合。
要触发清理,您有不同的可能性:
Two things to unpack here.
First, it is not advised to store files in the database. It's better to use a storage or directly the server's filesystem.
Second, files are usually uploaded and saved according to your strategy (on the server's filesystem, the database or a third party storage), and then a cleanup would happen if the user hasn't proceeded with the payment. You need to define the conditions for the cleanup to happen, whether it's because the user has uploaded file and has been inactive for a certain period of time, or because they click on a specific button, or a combination of both.
To trigger the cleanup, you have different possibilities: