Last active
March 7, 2018 01:22
-
-
Save fmasanori/5923199 to your computer and use it in GitHub Desktop.
gridfs mongo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymongo | |
import gridfs | |
import sys | |
con = pymongo.MongoClient("mongodb://localhost") | |
db = con.test | |
videos_meta = db.videos_meta | |
grid = gridfs.GridFS(db, 'videos') | |
f = open('extreme_video.mp4', 'r') | |
_id = grid.put(f) | |
f.close() | |
print ('id of file is ', _id) | |
videos_meta.insert({'grid_id':_id, 'filename': | |
'extreme_video.mp4'}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Para quem estiver utilizando Python 3 e está com o erro parecido abaixo:
Utilize na função
open()
, no parâmetro de mode'rb'
ao invés de só'r'
.O
'b'
entra em modo binário, assim possibilitando ler o arquivo.Exemplo:
Fonte: https://docs.python.org/3/library/functions.html#open