使用pymongo在Mongodb的GridFS中保存文件会导致截断文件 - Windows 7上的python 2.7

 广东没有名字的世界 发布于 2023-02-11 11:04

使用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

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有