hey all,

this isn't written totally generally but here is a shot.  i would like to 
return the raw binary data for an img src request and have it display 
properly on the html page.  here is my code:

the db.py table definition:

db.define_table('png',
    Field('input_date', 'date', comment='format YYYY-MM-DD', 
default=datetime.date.today(), writable=False, readable=False),
    Field('png', 'blob', comment='which in postgresql 9.1 is a confirmed 
bytea field type'),
    format = '%(id)s %(input_date)s')

and under default.py controller:

def png():
    t = TABLE(TR(TD('png record count: '+str(db(db.png.id>0).count()), 
_colspan='3')))
    qry = db(db.png.id>0).select()
    for q in qry:
        t.append(TR(TD(q.input_date), TD(IMG(_src=URL('default', 
'getbinary', args=['png', q.id, 'png'])))))
    return HTML(BODY(t))

def getbinary():
    data = 
db(db[request.args[0]].id==int(request.args[1])).select(db[request.args[0]][request.args[2]]).first()
    #data = base64.decodestring(data[request.args[2]])
    data = data[request.args[2]]
    response.headers['Content-Type'] = 'image/png'
    return response.write(data, escape=True)

where you can see i experimented with various "things" to try to get it to 
display properly under the browser.  i have a test png in the database and 
under postgresql it is confirmed to be 5513 bytes long in hex format.

can anyone suggest proper working code?  i believe the problem is in the 
getbinary function.  thank you in advance.  lucas

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to