Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from gevent import monkey; monkey.patch_all()
from gevent.pywsgi import WSGIServer
from pymongo import MongoClient
from gridfs import GridFS
from gridfs.errors import NoFile
#from bson import ObjectId
import sys
db = MongoClient(max_pool_size=15).example
fs = GridFS(db)
def application(environ, start_response):
path = filename='.' + environ['PATH_INFO']
try:
file = fs.get_last_version(filename=path);
except NoFile:
start_response('404 Not Found', [('Content-Type', 'text/plain')])
return [b'Not Found']
start_response('200 OK', [('Content-Type', 'image/jpeg')])
return [file.read()]
if __name__ == '__main__':
WSGIServer(('', 8080), application, log=None).serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.