On Friday, August 2, 2019 at 8:33:33 AM UTC-7, Константин Комков wrote:
>
> What do you want to know?
> tables.py
> db.define_table(
>     'recipes',
>     Field('NAME',length=512),
>     Field('IMAGE'),
>     migrate=False
> )
> It's my database connection in db.py:
> db = DAL('firebird://sysdba:masterkey@localhost/C:/HR.fdb', 
> ignore_field_case=True, entity_quoting=False, pool_size=1, migrate_enabled
> =False, db_codec='UTF-8')
>
>
You probably have to stream the object in the response.

def getmyblob():
    import cStringIO
    import os, shutil
    # print request
    if len(request.args) == 0 or not request.args[0]:
      raise HTTP(404, "unknown file not found")
    row = db(db.mypics.pname == request.args[0]).select().first()
    blob = db[somethingsomething].[copyblobltotmpfile]

    dst = os.path.join(request.env.web2py_path, "application", blob.tmpname)
    if not os.access(dst, os.F_OK):
            print dst
            raise HTTP(404,"funny, that's not here")
    imstat = os.stat(dst)    filedata=open(dst,"rb").read()
    response.headers['Content-Type']='image/jpeg'
    response.headers['Content-Length']=imstat.st_size
    return response.stream(cStringIO.StringIO(filedata))


Then your IMG tag looks like 
<IMG src="getmyblob/{{=blobrowid}} alt="image file for {{=blobrowid"}} 
title="={{blobrowid}}">

Sorry for the hacky look of this, I don't have much experience handling 
blobs; the code I use is for an image as an ordinary file in the 
filesystem.  (My app tags pictures transferred from my camera.)

The field type "upload", combined with the default/user/download() 
function, hides much of this from you, but has something similar under the 
hood.

Good luck!

/dps






-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/1173eb73-fe6c-482c-8c33-b1d83302d126%40googlegroups.com.

Reply via email to