-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdocs.py
More file actions
36 lines (29 loc) · 750 Bytes
/
docs.py
File metadata and controls
36 lines (29 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from application import mongo, fs
from mongokit import ObjectId
import base64
blob_collection = mongo.blobs
class Blob(object):
def __init__(self, data):
self.data = data
def read(self):
return self.data
def save(self):
f = fs.new_file()
f.write(self.data)
id = f._id
f.close()
return str(id) # str(blob_collection.insert({"data": self.data}))
@staticmethod
def find_one(id):
f = fs.get(ObjectId(id))
if f:
blob = Blob(f.read())
return blob
else:
return None
# record = blob_collection.find_one({"_id": ObjectId(id)})
# if record:
# blob = Blob(record['data'])
# return blob
# else:
# return None