Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-610

Saving a file in Mongodb's GridFS with pymongo results in a truncated file - python 2.7 on Windows 7

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.6.3
    • None
    • python 2.7
      Windows 7
      mongodb 2.2.3 (running on Ubuntu)

    Description

      Saving a file in Mongodb's GridFS with pymongo results in a truncated file.

      Example:

      from pymongo import MongoClient
      import gridfs
      import os

      #just to make sure we aren't crazy, check the filesize on disk:
      print os.path.getsize( r'owl.jpg' )

      #add the file to GridFS, per the pymongo documentation: http://api.mongodb.org/python/current/examples/gridfs.html
      db = MongoClient().myDB
      fs = gridfs.GridFS( db )
      fileID = fs.put( open( r'owl.jpg', 'r') )
      out = fs.get(fileID)
      print out.length

      On Windows 7, running this program generates this output:

      145047
      864

      On Ubuntu, running this program generates this (correct) output:

      145047
      145047

      so you can reproduce my example more rigorously, 'owl.jpg' was downloaded from: http://getintobirds.audubon.org/sites/default/files/photos/wildlife_barn_owl.jpg

      Attachments

        Activity

          People

            bernie@mongodb.com Bernie Hackett
            dustin Dustin Reagan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: