【发布时间】:2013-12-31 08:12:58
【问题描述】:
使用 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
【问题讨论】:
标签: python windows mongodb pymongo gridfs