On 9 янв, 08:51, Chris McDonough <[email protected]> wrote: > > Pyramid has nothing built-in for GridFS but this might > help:http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/fil... > > - C
Oh, Chris, Thank You so much, it works perfectly! I'll show what i did for those who might be interested: 1) I added a new subscriber to the configuration for Gridfs support like it shown in the cookbook http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/mongo.html 2) Then i added a new route to my app's __init__.py config.add_route('gridfs', '/gridfs/{filename}') 3)And the last thing we need to do is just write a view like this: from pyramid.httpexceptions import HTTPNotFound from gridfs import GridFS from gridfs.errors import NoFile @view_config(route_name='gridfs') def gridfs_get(request): fs = GridFS(request.db) filename = request.matchdict['filename'] try: f = fs.get_last_version(filename) except NoFile: return HTTPNotFound('File not found') response = Response(content_type=f.content_type) response.app_iter = f return response One this to note here is that mime-type of the file should be specified when you put it into GridFS, like this: fs.put(filedata, filename='ronpaul2012.jpg', content_type='image/ jpeg') then you will have ".content_type" property. More info: http://api.mongodb.org/python/current/api/gridfs/grid_file.html#gridfs.grid_file.GridIn.content_type http://mongodb.org/display/DOCS/GridFS+Specification I think, i'm really falling in love with Pyramid! ;) You know, so many good things are going on in my life right now, i was an outsider, couldn't find the GOAL for my life, but then i started to study spiritual literature, Vedic culture, i switched to raw food diet for a few month now, and i'm feeling so good, i have energy and passion to live! Chris McDonough, i've seen a video with You, You're a great person, thank you so much for all what you're doing... I love you guys! :D -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
