我在尝试从gridfs检索文件时遇到gridfs文件系统的问题,我能够使用carrierwave mongoid gridfs存储文件(文本,pdf)并且无法从mongodb获取数据,任何人都可以帮助我< / p>
我将示例文本文件上传到gridfs,它将文件内容存储在数据库中请查看以下记录,从中可以看到数据库中的实际记录
#<Email _id: 547f17f37261740ea9000000, from: "mail@gmail.com", to: "mail@gmail.com",
cc: nil, bcc: nil, subject: "testmail", body: "h1. Give RedCloth a try! A *simple*
paragraph with a line break , some_emphasis_and a \"link\":http://redcloth.org",
attachment1: #<BSON::Binary:0xe129374 @data="this is a simple file a couple of lines
long\nsecond line\nthird line", @type=:generic>, attachment2: nil, attachment3: nil>
看到字段attachment1它显示了gridfs内容,而@data存储了我的实际文件内容,直到这一切都很好,但当我尝试从这条记录中获取数据时我无法得到它,我试着像以下
@email.attachment1.read ==> shows me nil value
@email.attachment1.file.read => also shows me nil value
also tried @email.instance_variable_get(:@data) ==> not worked
如何解决这个问题,请帮助我。提前谢谢。