Skip to main content

async mongodb gridfs with tornado IOLoop

Project description

asyncgridfs
===========

async mongo gridfs for tornado


Installation
------------

Installing: `pip install asyncgridfs` or ` easy_install asyncgridfs`


Usage
-----

import asyncmongo
import tornado.web
from asyncgridfs import GridFS

class Handler(tornado.web.RequestHandler):
@property
def db(self):
if not hasattr(self, '_db'):
self._db = asyncmongo.Client(pool_id='mydb', host='127.0.0.1', port=27017, maxcached=10, maxconnections=50, dbname='test')
return self._db

@tornado.web.asynchronous
def get(self):
fid = self.get_argument('fid')
fs = GridFS(self.db)
fs.get(ObjectId(fid),callback=self._on_get)


@tornado.web.asynchronous
def post(self):
f = self.request.files['imgFile'][0]
content = f.pop('body')
content_type = f.pop('content_type')
filename = f.pop('filename')

fs = GridFS(self.db)
fs.put(content, contentType=content_type, filename=filename, callback=self._on_post)


def _on_get(self, fileobj):
self.set_header('Content-Type', fileobj['contentType'])
self.write(fileobj['data'])
self.finish()

def _on_put(self, _id):
self.write(str(_id))
self.finish()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncgridfs-0.2.dev.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file asyncgridfs-0.2.dev.tar.gz.

File metadata

  • Download URL: asyncgridfs-0.2.dev.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for asyncgridfs-0.2.dev.tar.gz
Algorithm Hash digest
SHA256 1d199dacacf919f388df5bd3e7b73cb74fa5771beac8dbb5cf62ef931fd7451d
MD5 51bbdd787a979e1a4eb5f422d1e08011
BLAKE2b-256 60a34ae88e4cf1d7a8618253b2bc67590b892fb9a958335fbc7a5bf7851504b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page