Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. from pymongo import MongoClient
  2. import gridfs
  3. import base64
  4. import sys
  5. import bson
  6. import json
  7. import os.path
  8.  
  9. save_path = "./files"
  10.  
  11. fs_file = sys.argv[1]
  12.  
  13. db = MongoClient("YOUR_DB_URI").test
  14. fs = gridfs.GridFS(db)
  15.  
  16.  
  17. filemeta = []
  18.  
  19. with open(fs_file) as f:
  20. data = bson.decode_all(f.read())
  21. for i in data:
  22. filemeta.append({"_id": i["_id"], "filename": i["filename"]})
  23. print(filemeta[-1])
  24. fileData = fs.get(i["_id"]).read()
  25. completeName = os.path.join(save_path, i["filename"])
  26. ff = open(completeName, "w")
  27. ff.write(fileData)
  28. ff.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement