I am trying to build a python-eve REST API with mysql backend and I would like to have a custom mediastorage backend. Basicly I want the filenames saved into database and files in filesystem.
Here is a draft of the mediastorage based on the GridFS in the core:
class CustomMediaStorage(MediaStorage):
def __init__(self, app=None):
super(CustomMediaStorage, self).__init__(app)
self.validate()
def validate(self):
if self.app is None:
raise TypeError('Application object cannot be None')
if not isinstance(self.app, Flask):
raise TypeError('Application object must be a Eve application')
def get(self, path, resource=None):
pprint(path)
_file = None
try:
_file = open(path, 'r')
except:
pass
return _file
def post(self, content, filename=None, content_type=None, resource=None):
pprint('post')
if(filename):
path = 'var/www/koodit/upload/'+filename
try:
_file = open(path, 'w')
_file.write(content)
_file.close()
except:
pass
return path
My specific problem here is that while the class catches the get-method the post-method does not seem to be able even to print out the comment.
Calling the media storage this way:
app = Eve(data=SQL,settings=SETTINGS, media=CustomMediaStorage)
From client side I tried to send the image as base64.
"file was expected, got 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/7QCEUGhvdG9zaG9wIDMu... instead.",