Rails3、gridfs 和 mongomapper:如何提供文件服务?发送数据?

发布于 2024-08-25 18:58:21 字数 606 浏览 7 评论 0原文

我目前正在开发一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不交电费瞎发啥光 2024-09-01 18:58:21

我使用rack-gridfs正是为了这个目的,将文件提供给浏览器。该插件来自 jnunemaker,他也编写了 mongomapper。您可能还想看看我的 fork ofgrip,其中我添加了更多文档和方法来查看附件是否存在:

github.com/parasew/grip

对于rails3,您需要执行以下步骤才能使rack-gridfs工作:

将以下内容添加到您的Gemfile中,

gem "jnunemaker-rack-gridfs", :git =>"git://github.com/jnunemaker/rack-gridfs.git"

然后将这些行添加到您的application.rb中(在类Application < ; Rails::Application block) - 将这些值替换为您的实际 mongodb 设置。

require 'rack/gridfs'
config.middleware.use Rack::GridFS, :hostname => 'localhost', :port => 27017, :database => "yourdatabase", :prefix => 'gridfs'

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

gem "jnunemaker-rack-gridfs", :git =>"git://github.com/jnunemaker/rack-gridfs.git"

then add these lines to your application.rb (in the class Application < Rails::Application block) - replace the values with your actual mongodb setup.

require 'rack/gridfs'
config.middleware.use Rack::GridFS, :hostname => 'localhost', :port => 27017, :database => "yourdatabase", :prefix => 'gridfs'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文