SHARE
TWEET

Untitled

a guest Sep 17th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top