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

How do I call a function with pymongo using webpy?
python motor offers fetch_next exception on aggregation
python motor mongo cursor length or peek next
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?

Categories

HOME
jboss
hdfs
theano
celery
fedora
telegraf
elastic-load-balancer
migrate
xamarin-zebble
match
lapack
colors
cname
angular4
feature-extraction
powermock
pywinauto
workday
pymongo
acl
substring
opentext
bitbake
openbr
source-insight
location-services
infopath2010
netbios
quick-nimble
overwrite
kendo-listview
devtools
cmis
nanogallery
forms-authentication
best-buy-api
fluid-mac-app-engine
reverse-dns
doctrine-extensions
spongycastle
rightnow-crm
dredd
ssi
mura
dblink
apache-modules
maatwebsite-excel
cocoa-bindings
nclam
spring-mongo
vimperator
preferenceactivity
ui4j
phpquery
featuretoggle
css-paged-media
gql
sequence-sql
darwin
relational-model
nanomsg
dos2unix
famo.us
dc
inputbox
visual-studio-6
code-complexity
rails-api
jchartfx
autonumber
quickgraph
postgres-xc
objective-c-runtime
notin
oscilloscope
xmlwriter
sfinae
server-name
liveconnect
qtextbrowser
net-use
nsrangeexception
multiple-users
3-tier
rational-unified-process
html-components
downcasting
datagridcolumn
parentid

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App