0

So I think I have done everything in order to server images and am unable to see an image even though I have followed the instructions precisely on this site:

http://jwage.com/2010/07/27/storing-files-with-mongodb-gridfs/

When I do:

 $dm = $this->get('doctrine.odm.mongodb.document_manager');

         $image = $dm->createQueryBuilder('MyBundle:Image')
                     ->field('id')->equals($imageID) //I have verified imageID to be correct
                     ->getQuery()
                     ->getSingleResult();
                     var_dump($image->getFile()->getBytes());

I get:

string(194992) ""

Which tells me that the image is there, just that I am unable to get the bytes using the following as that comes null:

echo $image->getFile()->getBytes();

Please note that I am able to see the image using RockMongo etc so I know image is stored properly plus I can see it in the database stored as chucks. So what is wrong???

UPDATE: I HAVE ATTACHED THE VAR_DUMP OF THE file object.

object(Doctrine\MongoDB\GridFSFile)#427 (4) {
  ["mongoGridFSFile":"Doctrine\MongoDB\GridFSFile":private]=>
  object(MongoGridFSFile)#430 (3) {
    ["file"]=>
    array(7) {
      ["_id"]=>
      object(MongoId)#431 (1) {
        ["$id"]=>
        string(24) "503302b3c7e24c401a000004"
      }
      ["name"]=>
      string(6) "Image2"
      ["filename"]=>
      string(14) "/tmp/phpBhZDAy"
      ["uploadDate"]=>
      object(MongoDate)#432 (2) {
        ["sec"]=>
        int(1345520307)
        ["usec"]=>
        int(983000)
      }
      ["length"]=>
      float(194992)
      ["chunkSize"]=>
      float(262144)
      ["md5"]=>
      string(32) "5bbc9ede74f50f93a3f7d1f7babe3170"
    }
    ["gridfs":protected]=>
    object(MongoGridFS)#437 (5) {
      ["w"]=>
      int(1)
      ["wtimeout"]=>
      int(10000)
      ["chunks"]=>
      object(MongoCollection)#438 (2) {
        ["w"]=>
        int(1)
        ["wtimeout"]=>
        int(10000)
      }
      ["filesName":protected]=>
      string(12) "assets.files"
      ["chunksName":protected]=>
      string(13) "assets.chunks"
    }
    ["flags"]=>
    int(0)
  }
  ["filename":"Doctrine\MongoDB\GridFSFile":private]=>
  NULL
  ["bytes":"Doctrine\MongoDB\GridFSFile":private]=>
  NULL
  ["isDirty":"Doctrine\MongoDB\GridFSFile":private]=>
  bool(false)
}
null
Strong Like Bull
  • 11,155
  • 36
  • 98
  • 169
  • How are you actually serving the images to the browser? Have you tried saving the image to a file first to confirm it can be retrieved OK? – Stennie Aug 24 '12 at 02:39
  • yes I have saved the images using persist and they appear in database – Strong Like Bull Aug 24 '12 at 05:27
  • So how are the images being served to the browser .. do you have a code example for that, since it seems to be the issue? – Stennie Aug 24 '12 at 05:40

0 Answers0