Hello

I have a database working with another system. I need to create some reports 
and 
I'm doing with web2py.

Simplifying model is as follows:

tb_padron = db.define_table('vwpadron',
    Field('nors'),    
    Field("marca", "blob"),
    Field("archivoimagen", "upload", uploadfield="marca"),
    migrate=False
)

field "marca" stores an image as blob type.

if I access from outside web2py:

cur = conn.cursor()
cur.execute("select marca from vwpadron where id=15;")
print cur.fetchall()

get (truncated for clarity):

[['\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x0...]]

obtained using the string in a controller function

def test_image():
    img='\xff\xd8\xff\xe0\x00\x10JFIF\...'
    response.headers['Content-Type']='image/jpg'    
    return img
    
I see the image correctly.


Now if I do the following:

def image2():
    marca = db(tb_padron.id==15).select(tb_padron.marca).first()
    return dict(marca=marca)

in view image2:

{{extend 'layout.html'}}
{{=marca.marca}}

get:

$R �5�=�m��Pj��Gv�㞻�ЃQ� 
��QU�a�y�!�;-��1�9�W�"�����������;����6�j��E�R�JSϟ���Gi;�_AU|Z�9�Uh�[�b���!�����R�J�F��L)��_��
 
��#@�(�#4�'ʍ6+�U 


In another attempt:

def imagen3():       
    marca = db.executesql("select marca from vwpadron where id=15;")
    return dict(marca=marca)

get (truncated for clarity):

[['\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\...']]

if I do the following:
return dict(marca=marca[0][0])

wanting to get: '\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\...'

but no, I get something else and I can not show as an image.

����JFIF��C    $.' 
",#(7),01444'9=82<.342��  `�� 
���}!1AQa"q2���#B��R��$3br� ...


Someone can help me with this. Encodings is a problem?

(I wonder if you understand?)

regards
Jose

Reply via email to