Created
September 6, 2019 00:13
-
-
Save L04DB4L4NC3R/a81be4f8ea80bb8839cd5e7d5030d56d to your computer and use it in GitHub Desktop.
get files
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
| from pymongo import MongoClient | |
| import gridfs | |
| import base64 | |
| import sys | |
| import bson | |
| import json | |
| import os.path | |
| save_path = "./files" | |
| fs_file = sys.argv[1] | |
| db = MongoClient("YOUR_DB_URI").test | |
| fs = gridfs.GridFS(db) | |
| filemeta = [] | |
| with open(fs_file) as f: | |
| data = bson.decode_all(f.read()) | |
| for i in data: | |
| filemeta.append({"_id": i["_id"], "filename": i["filename"]}) | |
| print(filemeta[-1]) | |
| fileData = fs.get(i["_id"]).read() | |
| completeName = os.path.join(save_path, i["filename"]) | |
| ff = open(completeName, "w") | |
| ff.write(fileData) | |
| ff.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment