Failed to load download file to store files running python-eve

I am trying to create a python-eve REST interface with mysql backend, and I would like to have my own mediastorage gateway file. Basically, I want the file names to be stored in the database and the files in the file system.

Here is a GridFS-based media project in the kernel:

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 is that although the class catches the get method, the post method does not seem to be able to even print a comment.

Call media storage as follows:

app = Eve(data=SQL,settings=SETTINGS, media=CustomMediaStorage)

On the client side, I tried to send the image as base64.

"expected to get 'data: image / jpeg; base64, / 9j / 4AAQSkZJRgABAgAAAQABAAD / 7QCEUGhvdG9zaG9wIDMu ... instead."

+4

Source: https://habr.com/ru/post/1651301/


All Articles