[英]Should I delete uploaded files from the file system on my own?
I have a rails app where the user can upload files. 我有一个Rails应用程序,用户可以在其中上传文件。 The files get uploaded to an external cloud service by a backgroud jobs.
通过backgroud作业将文件上传到外部云服务。 It's vital for my app that the files won't get stored in the file system after they've been uploaded.
对于我的应用程序而言,至关重要的是,文件上传后不会存储在文件系统中。 Not right away, in general -- they must not remain in the file system.
通常,不是马上就可以-它们一定不能保留在文件系统中。
Should I delete them on my own? 我应该自己删除它们吗? Or will get deleted automatically?
还是会自动删除?
Also, debugging my app, I noticied this for an attachment params: 另外,调试我的应用程序时,我注意到了附件参数:
[2] pry(#<MyController>)> my_params.tempfile.path
"/var/folders/qr/0v5z71xn7x503ykyv1j6lkp00000gn/T/RackMultipart20181007-10937-3ntmgg.png"
That file gets stored not in "/tmp" but in "/var" and that means that it won't get deleted automatically, right? 该文件不是存储在“ / tmp”中,而是存储在“ / var”中,这意味着它不会被自动删除,对吗?
Note that I'm not using paperclip for this task. 请注意,我没有为此任务使用回形针。
You are right the files won't get deleted automatically. 没错,文件不会自动删除。 You have to delete the file explicitly at some point in time.
您必须在某个时间点明确删除该文件。
It depends how you set it up. 这取决于您如何设置。 If you used Tempfile to save it then yes the files will be deleted when the object is garbage collected.
如果使用Tempfile进行保存,则可以,当对象被垃圾回收时,文件将被删除。 If not then it probably won't be deleted.
如果没有,那么它可能不会被删除。
If the files get stored on an external service it might be worth setting up ActiveStorage which allows you to directly upload to external storage providers without the file ever touching your server. 如果文件存储在外部服务上,则可能值得设置ActiveStorage ,它使您可以直接上传到外部存储提供商,而无需碰到服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.