Ejemplo n.º 1
0
    def test_get(self):
        fs = GridFS(self.db,'fs')

        def put_cb(_id):
            def noop_callback(response):
                print response
                logging.info(response)
                loop = tornado.ioloop.IOLoop.instance()
                # delay the stop so kill cursor has time on the ioloop to get pushed through to mongo
                loop.add_timeout(time.time() + .1, loop.stop)

            fs.get(_id,noop_callback)

        fs.put("78hlkjhg90ik75678", file_name = "a.png", contentType="image/png", 
                                    chunk_size = 3,
                                    callback = put_cb)

        #fs.list(noop_callback)

        #def find_callback(res, error):
        #    print res,error
        #    tornado.ioloop.IOLoop.instance().stop()
        #
        #fs.find({'contentType':'image/png','code_name':'test-0000-a'},callback=noop_callback)
        tornado.ioloop.IOLoop.instance().start()
Ejemplo n.º 2
0
def file_page(page,size=10,ftype='image', callback=None):
    db = get_context().get_asyncmongo()
    if ftype=='image':
        fs = GridFS(db,THUMBNAIL_GFS)
    elif ftype=='file':
        fs = GridFS(db,FILE_GFS)
    
    fs.find(skip=(page+1)*size,limit=size,callback=None)
Ejemplo n.º 3
0
def del_image(fid):
    fid = ObjectId(fid)
    db = get_context().get_asyncmongo()
    tfs = GridFS(db, THUMBNAIL_GFS)
    yield gen.Task(tfs.delete, fid)

    fs = GridFS(db, IMG_GFS)
    yield gen.Task(fs.delete, fid)
Ejemplo n.º 4
0
def get_file(fid, ftype, callback=None):
    db = get_context().get_asyncmongo()

    if ftype=='image':
        fs = GridFS(db, IMG_GFS)
    elif ftype=='thumbnail':
        fs = GridFS(db, THUMBNAIL_GFS)
    elif ftype=='file':
        fs = GridFS(db, FILE_GFS)
    
    fid = ObjectId(fid)
    fs.get(fid, callback=callback) 
Ejemplo n.º 5
0
def put_image(body, filename, fmt, **kwargs):
    db = get_context().get_asyncmongo()
    kwargs.update(filename=filename)
    fs = GridFS(db, IMG_GFS)

    try:
        body = _resize_image(body, fmt, __conf__.IMG_MAX_SIZE)
        fid = yield gen.Task(fs.put, body, **kwargs)
        thumbnail = _resize_image(body, fmt, __conf__.THUMBNAIL_SIZE)

        tfs = GridFS(db, THUMBNAIL_GFS)
        tfid = yield gen.Task(tfs.put, thumbnail, _id=fid, **kwargs)
    except Exception as e:
        yield gen.Task(fs.delete, fid)
        print e
        raise

    raise gen.Return(fid)
Ejemplo n.º 6
0
def get_file(fid, ftype, callback=None):
    db = get_context().get_asyncmongo()

    if ftype == 'image':
        fs = GridFS(db, IMG_GFS)
    elif ftype == 'thumbnail':
        fs = GridFS(db, THUMBNAIL_GFS)
    elif ftype == 'file':
        fs = GridFS(db, FILE_GFS)

    fid = ObjectId(fid)
    fs.get(fid, callback=callback)
Ejemplo n.º 7
0
def file_page(page, size=10, ftype='image', callback=None):
    db = get_context().get_asyncmongo()
    if ftype == 'image':
        fs = GridFS(db, THUMBNAIL_GFS)
    elif ftype == 'file':
        fs = GridFS(db, FILE_GFS)

    fs.find(skip=(page + 1) * size, limit=size, callback=None)
Ejemplo n.º 8
0
def put_file(body, filename, **kwargs):
    db = get_context().get_asyncmongo()
    fs = GridFS(db, FILE_GFS)
    kwargs.update(filename=filename)
    fs.put(body,**kwargs)
Ejemplo n.º 9
0
def put_file(body, filename, **kwargs):
    db = get_context().get_asyncmongo()
    fs = GridFS(db, FILE_GFS)
    kwargs.update(filename=filename)
    fs.put(body, **kwargs)