在只读文件系统上使用 Rails 提供临时文件
我现在正在将我的应用程序部署到具有只读文件系统的服务器。我正在使用 gem 制作一个 zip 文件并随机将其放入 /public 某处。现在我只能写入 tmp - 如何为 tmp 文件夹中的文件的用户提供服务?
I'm deploying my apps now to a server that has a read only file system. I was using a gem to make a zip file and randomly plopping it in /public somewhere. Now I can only write to tmp - how do I serve the user that file out of the tmp folder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我最终没有使用任何这些方法。我在 Heroku 上,我需要提供的图像/文件量不足以保证云存储。
我所做的是使用一种方法在 tmp 中创建一个文件,并使用
link_to_remote
链接到该文件以生成该文件。另一个链接指向一个操作,该操作使用send_file
以及我在 temp 中创建的文件的路径。我遇到的问题是由于使用相同的方法进行生成和文件服务,我将尝试弄清楚并可能发布另一个问题。
I ended up not using any of these methods. I am on Heroku, and the amount of images/files I need to serve isn't large enough to warrant cloud storage.
What I did was create a file in tmp using one method and linking to it with
link_to_remote
to generate the file. Another link was made to an action which usessend_file
with the path of the file I created in temp.The problems I was having was due to doing the generation and file serving being IN THE SAME method, which I will try to figure out and possibly post another question on.
你真的不想这样做——这是一个巨大的安全风险。
You really don't want to do that - it's a huge security risk.
一种可能性是将其作为 BLOB 存储在数据库中。
One possibility would be to store it as a BLOB in your database.
当你必须提供文件时,为什么要使用只读(我假设是 Heroku?)?看起来你正在逆流而上。我会使用 AWS 实例。您可以获得可靠性、访问权限和带宽。不是免费的,但什么是免费的?
Why would you use a read-only (I'm assuming Heroku?) when you have to serve files? Seems like you're swimming upstream. I'd use an AWS instance. You get the reliability, access and bandwidth. Not free, but what is?