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

Spark Streaming: foreachRDD insert into mongoDB using python?
how to find right version of bson from pip for pymongo/mongoengine
How to enable `projection` in pymongo query class `find()`?
Variables don't hold value for very long pymongo ipython
pymongo upgrade to 3.0.3 causes this statement to fail
UUID to NUUID in Python
how to test for empty mongodb query in pymong
read video file from mongodb with pymongo
Get OperationFailure error with PyMongo 2.7.1
Inserting string as regular string in mongodb
Mongos + Pymongo 2.5 ==>No suitable hosts found
pymongo collection add item using update
How to convert objectid to string
Conditional atomic mongo remove with different results
python script to connect to mongodb master
flask-admin and pymongo search

Categories

HOME
class
weblogic12c
clearcase
barcode-scanner
mousemove
dafny
nsview
mathematical-optimization
moodle-api
linker
supercollider
scheduler
gtk
parsley.js
android-externalstorage
spring-amqp
outlook-restapi
squirrel-sql
corona
async-await
bnf
uima
tfsbuild
http-authentication
akka-persistence
sharedpreferences
substring
mod-wsgi
basex
ccavenue
locks
matlab-app-designer
xcrun
advanced-filter
counting
android-canvas
amazon-kms
testlink
recovery
extbase
export-to-pdf
word-cloud
nomad
visual-format-language
skip-lists
winmerge
mongodb-aggregation
gnome-terminal
case-when
rcharts
mechanicalturk
maatwebsite-excel
java-2d
livecycle
pyaudio
seccomp
static-methods
okta-api
helm
textpattern
variable-length-array
mixins
enaml
prism-4
mojo
createfile
adhoc-polymorphism
mobile-country-code
mod-perl
spring-security-acl
strcmp
ctp
disjoint-union
postgres-xc
apportable
acceptance-testing
pacman
examine
lynx
playorm
clrprofiler
getopt-long
wcf-callbacks
data-dump
nsconnection
solandra
sscli
android-input-method
projectpier
.net-client-profile
subtext
index.dat
account-management

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App