使用pymongo在Mongodb的GridFS中保存文件会导致截断文件.
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
在Windows 7上,运行此程序会生成以下输出:
145047 864
在Ubuntu上,运行此程序会生成此(正确)输出:
145047 145047
不幸的是,我正在开发的应用程序是针对Windows操作系统的......
任何帮助,将不胜感激!
所以你可以更严格地再现我的例子,'owl.jpg'是从以下网址下载的:http://getintobirds.audubon.org/sites/default/files/photos/wildlife_barn_owl.jpg