简体   繁体   English

我应该自己从文件系统中删除上传的文件吗?

[英]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.

相关问题 Heroku删除我上传的文件,为什么? - Heroku delete my uploaded files, why? 如何防止capistrano覆盖用户在自己的文件夹中上传的文件? - How do I prevent capistrano from overwriting files uploaded by users in their own folders? 我应该如何格式化防护文件以监视除日志文件之外的所有文件? - How should I format my guard file to watch all files apart from log files? 滑轨,滚动自己的身份验证系统,我应该考虑哪些安全问题? - rails, rolling my own authentication system, what are security issues I should be taking into consideration? 我应该编写自己的CMS吗? - Should I write my own CMS? 我应该复制/粘贴从Spree到我自己的应用程序的所有控制器和路由吗? - Should I copy/paste all controllers and routes from Spree to my own app? 如何从我的索引文件中查看活动存储上传的图像,出现此错误 - how do i view an active storage uploaded image from my index file, this error comes up 我应该把我自己的不是模型/视图/控制器的类放在哪里? - Where should I put my own classes that are not models/views/controllers? 我应该在rails应用程序中将自己的“模块”放在哪里? - Where should I place my own “module” within rails application? 从ActionController登录到我在Rails中的文件吗? - Logging to my own file in Rails from an ActionController?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM