Rails3、gridfs 和 mongomapper:如何提供文件服务?发送数据?
我目前正在开发一个rails3应用程序,带有mongomapper和gridfs中的文件存储。 经过一番尝试后,我发现了握力,目前也在应用程序中使用它来存储数据。到目前为止,一切都很好 - 现在我正在努力为用户提供文件 - 实现这一目标的最佳/最快方法是什么?
从: http://railstips.org/blog /archives/2009/12/23/getting-a-grip-on-gridfs/
似乎有两种方法:
- 从 ruby/rails 发送数据 - 这是推荐的方法吗?够快吗? (我想在部署设置中使用乘客)
- 编写 Rails Metal(请参阅 http://gist.github.com /264077) - 关于如何将其与rails3一起使用的任何评论或提示?
还有其他想法甚至例子吗? 多谢!
i am currently developing a rails3 app with mongomapper and file storage in gridfs.
after some trying around, i found grip and currently also use it in the app for storing the data. so far, so good - now i am trying to get my head around serving the files to the user -- what would be the best/fastest way to achieve that?
from:
http://railstips.org/blog/archives/2009/12/23/getting-a-grip-on-gridfs/
there seem to be 2 ways:
- send_data from ruby/rails - is this a recommended way? fast enough? (i want to use passenger in the deploy setup)
- writing a rails metal (see http://gist.github.com/264077) - any comments or hints on how to use that with rails3?
any other ideas or even examples?
thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用rack-gridfs正是为了这个目的,将文件提供给浏览器。该插件来自 jnunemaker,他也编写了 mongomapper。您可能还想看看我的 fork ofgrip,其中我添加了更多文档和方法来查看附件是否存在:
github.com/parasew/grip
对于rails3,您需要执行以下步骤才能使rack-gridfs工作:
将以下内容添加到您的Gemfile中,
然后将这些行添加到您的application.rb中(在类Application < ; Rails::Application block) - 将这些值替换为您的实际 mongodb 设置。
I am using rack-gridfs for exactly that purpose to serve files to the browser. The plugin is from jnunemaker, who also wrote mongomapper. you might also want to take a look at my fork of grip, where i added some more documentation and methods to see if an attachment exists:
github.com/parasew/grip
for rails3, you need the following steps to get rack-gridfs working:
add the following to your Gemfile
then add these lines to your application.rb (in the class Application < Rails::Application block) - replace the values with your actual mongodb setup.