Created
September 14, 2015 20:53
-
-
Save jcarlosgarcia/7c06989ab3dd4d931a76 to your computer and use it in GitHub Desktop.
GridFS and Bottle example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bottle | |
import pymongo | |
import gridfs | |
from bottle import response | |
# this is the handler for the default path of the web server | |
@bottle.route('/img/<filename>') | |
def show_img(filename): | |
# connect to mongoDB | |
connection = pymongo.MongoClient('localhost', 27017) | |
# attach to test database | |
db = connection.test | |
fs = gridfs.GridFS(db, "images") | |
fsout = fs.get_last_version(filename=filename) | |
response.content_type = 'image/jpeg' | |
return fsout | |
bottle.run(host='localhost', port=8082, reloader=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please note that you have to insert your files like this: