Simone and others,

I solved the DAL base64 encoding "problem". I read the field using 
cx_Oracle directly, not DAL. I dont know if there is another easier 
solution for this. Anyway, now I can go foward!

Follows the function to read the blob field:

def readPDFContent(query_parameters_here):
    blobselect = cx_Oracle.connect('usraudien/u$raud1en@SUAP')
    cursor = blobselect.cursor()
    cursor.execute(
                '''select your_blob_field
                    from ...
                ''', {query_parameters_here})
    row = cursor.fetchone()
    blobfield = row[0].read()   #read() must be before the cursor.close()!
    cursor.close()
    return blobfield

Fred

Em segunda-feira, 18 de novembro de 2013 14h02min47s UTC-3, Fred Guedes 
Pereira escreveu:
>
> Hi Simone,
>
> It really is a PDF file (I checked)! It´s a legacy database, the blob 
> field was not filled by DAL, but by another system (in Java). I guess a 
> base64 decode is going on incorrectly when the DAL reads the database. I 
> tried to replace the Field type parameter from 'blob' to 'SQLCustomType', 
> but it didnt work. It doenst read the field's value from DB.
>
> Field("lb_documento", "blob")
>
> Field("lb_documento", type=SQLCustomType(type='string', native='blob'))
>
> In the first declaration the field came "base64 decoded". When using the 
> second one, the blob field is not read from DB. 
>
> Do you know any way to read a native blob field using DAL without decode 
> it ?
>
> Thanks a lot,
> Fred
>
> Em segunda-feira, 18 de novembro de 2013 12h53min39s UTC-3, Niphlod 
> escreveu:
>>
>> you were the one saying that the column hold the content of the pdf file 
>> ^_^
>> DAL uses base64 to put the contents in.....
>> If you need to convert from base64, use a StringIO and then fill it with 
>> the decoded value, and stream that one.
>>
>> Simone
>>
>> On Monday, November 18, 2013 4:05:49 PM UTC+1, Fred Guedes Pereira wrote:
>>>
>>> Hi Niphlod,
>>>
>>> It worked! No need for StringIO. I just returned the blob field as the 
>>> http response content. The code:
>>>
>>> def pdfdoc():
>>>     evento = session._eventos[int(request.args(0))] or 
>>> redirect(URL('eventos'), args=request.args(0))
>>>     response.headers['Content-Type'] = 'application/pdf'
>>>     response.headers['Content-Disposition'] = 'attachment; 
>>> filename="teste.pdf"'
>>>     return evento['lb_documento']  #lb_documento is a blob field in an 
>>> Oracle DB, mapped with a 'blob' type with DAL
>>>
>>> BUT (always have a but!), the blob content (PDF) seems to be encoded. 
>>> When I open the resulting downloaded file it is not recognized as a PDF 
>>> file. I put a print just after retrieve the field from DB and it seems 
>>> enconded (base64?). But it´s another problem.
>>>
>>> Fred
>>>
>>> Em quinta-feira, 14 de novembro de 2013 14h21min37s UTC-3, Fred Guedes 
>>> Pereira escreveu:
>>>>
>>>> Hello,
>>>>
>>>> Is there a way to return PDF content generated from a blob db field? 
>>>>
>>>> My table has a blob field whose content is PDF. I would like to create 
>>>> a 'PDF page' from those bytes and return it.
>>>>
>>>> Thanks,
>>>>
>>>> Sorry for possible duplication.
>>>>
>>>> Fred
>>>>
>>>

-- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to