I'm building a flask application where I will be serving small images. These images are stored in MongoDB as BinaryData. In a helper function, I can store the data with these lines of python:
a = {"file_name": f, "payload": Binary(article.read())}
ARTICLES.insert(a)
I'm trying to build a class that contains the image. However, I cannot find the correct field declaration
class BinaryFile(mongo.Document):
created_at = mongo.DateTimeField(default=datetime.datetime.now, required=True)
file_name = mongo.StringField(max_length=255, required=True)
payload = mongo.Binary()
producing this error:
AttributeError: 'MongoEngine' object has no attribute 'Binary'
Can anyone suggest the correct way to declare this value or am I completely off base? This page does not provide a way to declare a field as Binary: http://api.mongodb.org/python/current/api/bson/index.html
Thanks!