Skip to content

Instantly share code, notes, and snippets.

@pkulev
Created August 26, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkulev/3ad25df42e36d26b0d28 to your computer and use it in GitHub Desktop.
Save pkulev/3ad25df42e36d26b0d28 to your computer and use it in GitHub Desktop.
import gridfs
import pymongo
conn = pymongo.MongoClient("mongodb://localhost:27017")
db = conn.test
videos_meta = db.videos_meta
def main():
grid_id = videos_meta.find_one({"filename": "video.mp4"})["grid_id"]
print("Filename grid id: %s" % grid_id)
grid = gridfs.GridFS(db, "videos")
print("File found: %s " % grid.exists(grid_id))
fd = grid.get(grid_id)
with open("video1.mp4", "wb") as fdout:
fdout.write(fd.read())
print("Done.")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment