slide-show image from MongoDB GridFS chunks @ D...

from pymongo import Connection, objectid
import gridfs
import imghdr

def slide(request):
    '''
    slide show image from MongoDB GridFS chunks, test only.
    '''
    try:
        _i = request.GET['_i']
        db = Connection().media_pool # connecting to database `media_pool`
        fs = gridfs.GridFS(db)
        _id = objectid.ObjectId(_i)
        img = fs.get(_id).read()
        mt = 'image/' + imghdr.what('', img)

        return HttpResponse(img, mimetype=mt)
    except KeyError:
        pass

    return HttpResponse("TEST Page")

 

<h1>TEST Page</h1>
<div id="output">
<script>
var src = '?_i=4dea26c64f6d001039000000';
document.getElementById('output').innerHTML = '<img height="100" width="100" src="' + src + '" />';
</script>
</div>

 

你可能感兴趣的:(mongodb,image,django,GridFS,slide-show)