0

I am getting issues with gridfs file system when try to retrieve files from gridfs, I could able to store files(text,pdf) using carrierwave mongoid gridfs and unable to get the data from the mongodb , Can anyone please help me

I uploaded sample text file into gridfs , it stored the file content in database please look at the following record where you can see the actual record from database

#<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>

see the field attachment1 it show you the gridfs content and @data stores my actual file content , upto this all is fine , but when I try to get the data from this record I am unable to get it , I tried like the following

@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 

How to fix this , please help me . Thanks in advance .

  • What exactly do you mean with "you are unable to get the data"? How exactly did you store the data, how do you try to retrieve it, and what kind of error condition does occur? Please [edit](http://stackoverflow.com/posts/27274983/edit) your question and add the relevant sourcecode and error description. – Philipp Dec 03 '14 at 15:20
  • I updated question please look at it – Ratnakar Vanapalli Dec 03 '14 at 15:39

0 Answers0