Question

I know we now can upload/post a media type field to the python-eve REST-API framework and it will be stored in mongodb. Is there a way we can change the storage of those media? E.g. a remote storage server e.g. amazon S3? So that we only store the URL of the image in mongodb instead of the whole image?

Was it helpful?

Solution

While the standard behaviour is to store on GridFS, you can also provide your own MediaStorage subclass which can store wherever you want to (file system, S3, etc.)

Something like this would do the trick:

from eve.io.media import MediaStorage

class AmazonS3MediaStorage(MediaStorage):
    """ Your actual implementation """
    pass

app = Eve(media=AmazonS3MediaStorage)

if __name__ == '__main__':
    app.run()

Check out the actual MediaStorage class for implementation details and/or see the actual GridFSMediaStorage class for reference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top