使用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下载的
你已经得到了答案,但是出于好奇:
http://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
嘿,换衣服
致:
修复了Windows 7上程序的行为。太糟糕了操作系统之间的行为不同。。。
相关问题 更多 >
编程相关推荐