Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to upload image through python-eve to some external storage server e.g. S3?

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?

like image 829
John Avatar asked Feb 17 '14 08:02

John


1 Answers

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.

like image 197
Nicola Iarocci Avatar answered Nov 15 '22 00:11

Nicola Iarocci