pymongo


read video file from mongodb with pymongo


I have a large video file stored in MongoDB gridFS.
I would like to read it and write it on my disk.
I can find the file in the database with:
file = grid_fs.find_one({"filename":'file_in_database.cin'})
I get back a grid out object gridfs.grid_file.GridOut at 0xa7b7be0
I try to write the file on my disk with:
with open('file_from_database.cin', 'w') as f:
f.write(file.read())
I get the file written but the size of the one download from the database is slightly different from the original size of the file:
05/15/2015 09:09 AM 65,585,808 file_from_database.cin
08/01/2007 01:08 PM 65,585,800 Original_file.cin
I checked the file in the database and the md5 field is the same as the original so the problem must be during the download or writing.
I'm using win7 64 and anaconda64 dirstribution for python 2.7
Any help would be appreciated.
Update
I tried the same code with a jpeg image and I get the same problem, the image is stored well in the database but when I get it and write it to the disk the size is slightly different and I cannot read it.
03/20/2015 02:36 PM 5,422,339 original_image.JPG
05/15/2015 02:44 PM 5,438,750 image_from_database.JPG
Am I doing some simple mistake reading the gridout and writing to the disk?
interesttingly if I open the image with:
PIL.Image.open(file)
I can get the image fine. Any Idea?

Related Links

PyMongo check if update succeeded
insert and query an OrderedDict in MongoHQ
Return .str of ObjectID using pymongo
Selecting the lowest/highest with find_one in Pymongo
Safe use of Pymongo's find_one
Pymongo $in + $regex
How can I get pymongo to always return str and not unicode?
SON Manipulator in mongo queries
How to append a document to a 2nd level embedded model list document in Django and mongoengine
pymongo multiple update $in
How to get negetive of a complex where clause in mongo db
pymongo justOne & multi
How to make pymongo's find() return a list?
convert pymongo cursor to json
How to do query on pymongo and get values in the reverse order of inserting
How to sort result by field?

Categories

HOME
events
plesk
weblogic12c
functional-programming
openxml
schema.org
hid
mongoid
mathematical-optimization
qooxdoo
apache-kafka-connect
ontology
fedora
minecraft
kurento
cocotb
amazon-emr
live-streaming
mpu6050
phonegap-build
google-cloud-logging
closures
psql
tableview
web-analytics
fido-u2f
liferay-6.2
connection-refused
backendless
prompt
running-object-table
unmarshalling
copy-protection
dotcms
universal
char-pointer
dreamfactory
jslint
strapi
cheat-engine
suds
pyttsx
word-cloud
web-inspector
apache-toree
vesta
doctrine-extensions
nonlinear-functions
predicates
gmaps.js
kendo-treeview
google-shopping-api
d3v4
ternary-operator
cefpython
pjax
thread-exceptions
openseadragon
odp.net-managed
jemdoc
polymerfire
outlook.com
darwin
quercus
python-c-extension
fiware-bosun
nhibernate-criteria
encryption-symmetric
rubber
iplimage
otl
maven-central
distributed-r
jchartfx
particle-swarm
compiler-flags
saga
mp4parser
indesign-server
bcdedit
eager-loading
struts2-json-plugin
voice-recording
thejit
taskkill
cakeyframeanimation
boost-foreach
azure-acs
qcar-sdk
hungarian-notation
sscli
asdoc
inversion
xap
accumulator
twitter-feed
regioninfo
jvm-bytecode
parentid

Resources

Encrypt Message