首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Monogid4 Gridfs连接失败

Monogid4 Gridfs连接失败
EN

Stack Overflow用户
提问于 2014-01-06 06:06:46
回答 2查看 234关注 0票数 0

我正在研究Rails4、Mongoid4和Gridfs。我无法连接gridfs文件系统。

代码语言:javascript
运行
复制
class GridfsController < ApplicationController
  def serve
    gridfs_path = env["PATH_INFO"].gsub("/uploads/", "")
    begin
     gridfs_file = Mongo::GridFileSystem.new(Mongo::DB.new('database_name', Mongo::Connection.new('localhost'))).open(gridfs_path, 'r')
    self.response_body = gridfs_file.read
    self.content_type = gridfs_file.content_type
   rescue Exception => e
    self.status = :file_not_found
    self.content_type = 'text/plain'
    self.response_body = ''
    raise e
  end
 end
end

得到这个错误

NameError (未初始化常量GridfsController::Mongo):

app/controllers/gridfs_控制员.in:7:in‘’

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-01-06 06:54:06

Mongoid不使用“官方”Ruby驱动程序与MongoDB对话,这就是Mongo::GridFileSystem的来源。蒙古人用摩托和MongoDB交谈,而摩托对GridFS一无所知。

AFAIK通常的GridFS解决方案是使用文件系统与GridFS对话:

代码语言:javascript
运行
复制
self.response_body = Mongoid::GridFs[gridfs_path].data

或者如果您使用的是id而不是路径:

代码语言:javascript
运行
复制
self.response_body = Mongoid::GridFs.get(gridfs_id).data
票数 0
EN

Stack Overflow用户

发布于 2014-06-25 13:24:08

这里有一个针对摩托驱动程序的gridfs规范的实现:摩托-格雷斯

这比装载两个司机(摩托和芒果红宝石司机)要好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20944010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档