[web2py] Re: return binary

2018-06-15 Thread Anthony
On Thursday, June 14, 2018 at 11:17:56 PM UTC-4, 黄祥 wrote:
>
> submit on this :
> https://github.com/web2py/web2py/issues
>

Actually, this would be a pydal 
issue: https://github.com/web2py/pydal/issues

Anthony

-- 
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.


[web2py] Re: return binary

2018-06-14 Thread 黄祥
submit on this :
https://github.com/web2py/web2py/issues

pls related the description with this google group discussion (url)

best regards,
stifan

-- 
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.


[web2py] Re: return binary

2018-06-14 Thread lucas
thank you, that would be wonderful.  where do I open the ticket?

-- 
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.


[web2py] Re: return binary

2018-06-14 Thread Massimo Di Pierro
We would need to create a custom adapter for this. Not hard to do, please 
open a ticket and we will get it done.

On Thursday, 14 June 2018 06:54:51 UTC+2, lucas wrote:
>
> so this is what i got working wonderfully but using psycopg2 directly 
> instead of the DAL.  AGAIN, i would love to convert this back to the DAL 
> for seemlessness and grace.
>
> def getbinary():
> try:
> c = psycopg2.connect("dbname='tms' host='%s' user='%s' 
> password='%s'" % ('localhost', 'username', 'passwd'))
> q = c.cursor(cursor_factory=psycopg2.extras.DictCursor)
> q.execute('select png from png where (id = 1);')
> data = StringIO(q.fetchone()[0])
> c.commit()
> finally:
> if ('q' in locals()) and (q is not None):
> q.close()
> if ('c' in locals()) and (c is not None):
> c.close()
> #bos...optional until eos and here to double check the binary read via 
> a pure file
> f = open('/opt/web-apps/web2py/applications/tms/out1.png', 'wb')
> f.write(data.getvalue())
> f.close()
> data.seek(0)
> #eos
> response.headers['Content-Type'] = 'image/png'
> return response.stream(data, 1024)
>
>

-- 
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.


[web2py] Re: return binary

2018-06-13 Thread lucas
so this is what i got working wonderfully but using psycopg2 directly 
instead of the DAL.  AGAIN, i would love to convert this back to the DAL 
for seemlessness and grace.

def getbinary():
try:
c = psycopg2.connect("dbname='tms' host='%s' user='%s' 
password='%s'" % ('localhost', 'username', 'passwd'))
q = c.cursor(cursor_factory=psycopg2.extras.DictCursor)
q.execute('select png from png where (id = 1);')
data = StringIO(q.fetchone()[0])
c.commit()
finally:
if ('q' in locals()) and (q is not None):
q.close()
if ('c' in locals()) and (c is not None):
c.close()
#bos...optional until eos and here to double check the binary read via 
a pure file
f = open('/opt/web-apps/web2py/applications/tms/out1.png', 'wb')
f.write(data.getvalue())
f.close()
data.seek(0)
#eos
response.headers['Content-Type'] = 'image/png'
return response.stream(data, 1024)

-- 
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.


[web2py] Re: return binary

2018-06-13 Thread lucas
PostGreSQL 9 which stores the png as direct raw non-escaped hex.  AND i am 
trying a direct sql select by using psycopg2 right now.  because using the 
DAL has been annoying.  but i'd love to use it if i could.  so i'm open to 
DAL methods.

-- 
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.


[web2py] Re: return binary

2018-06-13 Thread Dave S


On Wednesday, June 13, 2018 at 6:50:44 PM UTC-7, lucas wrote:
>
> so, i've figured out that the entire blob stream is not being fully 
> retrieved, only 29 of the 5513 bytes are being retrieved:
>
> in my debugging: here is an experimental / expanded of the above 
> function:::
> table, id, field, stream, and d are all working.  but the d[field] under 
> stream.write(d[field]) seems to only retrieve 29 bytes of the 5513 total 
> bytes, as verified by the binary file write i have below.
>
> def getbinary():
> table = db[request.args[0]]
> id = int(request.args[1])
> field = table[request.args[2]]
> try:
> stream = StringIO()
> d = db(table.id==id).select(field).first()
> stream.write(d[field])
> except:
> return CAT('exception getbinary():', BR(), 'table:', table, 
> type(table), BR(), 'id:', id, type(id), BR(), 'field:', field, type(field))
> #data = base64.b64decode(data)
> #data = data.decode('base64')
> f = open('/opt/web-apps/web2py/applications/tms/out1.png', 'wb')
> f.write(stream.getvalue())
> f.close()
> return CAT(type(stream), BR(), stream)
> response.headers['Content-Type'] = 'image/png'
> return response.write(data, escape=False)
>
>
I have no concrete suggestions, but which DB back end are you using?  
Handling blob fields are, AIUI, one of the ways they differ.

I have this silly thought that it's something like the string "truncation" 
you get when UTF-16 is viewed as a string.

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


[web2py] Re: return binary

2018-06-13 Thread lucas
so, i've figured out that the entire blob stream is not being fully 
retrieved, only 29 of the 5513 bytes are being retrieved:

in my debugging: here is an experimental / expanded of the above function:::
table, id, field, stream, and d are all working.  but the d[field] under 
stream.write(d[field]) seems to only retrieve 29 bytes of the 5513 total 
bytes, as verified by the binary file write i have below.

def getbinary():
table = db[request.args[0]]
id = int(request.args[1])
field = table[request.args[2]]
try:
stream = StringIO()
d = db(table.id==id).select(field).first()
stream.write(d[field])
except:
return CAT('exception getbinary():', BR(), 'table:', table, 
type(table), BR(), 'id:', id, type(id), BR(), 'field:', field, type(field))
#data = base64.b64decode(data)
#data = data.decode('base64')
f = open('/opt/web-apps/web2py/applications/tms/out1.png', 'wb')
f.write(stream.getvalue())
f.close()
return CAT(type(stream), BR(), stream)
response.headers['Content-Type'] = 'image/png'
return response.write(data, escape=False)

-- 
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.