From: Zhang H. <zhb...@gm...> - 2009-06-05 14:46:31
|
Hi, list. Is there ny example to display jpegPhoto stored in LDAP as base64 format? I only found example to add jpegPhoto in python-ldap-2.3.8/Demo/simple.py. Thanks very much. :) -- Best regards. Zhang Huangbin - Open Source Mail Server Solution for RHEL, CentOS, Debian, Ubuntu: + Homepage: http://code.google.com/p/iredmail/ + Forum: http://www.iredmail.org/forum/ |
From: Michael S. <mi...@st...> - 2009-06-05 19:27:51
|
Zhang Huangbin wrote: > > Is there ny example to display jpegPhoto stored in LDAP as base64 format? Not sure what you really want to display and where. How about entry['jpegPhoto'][0].encode('base64') ? Or are you talking about LDIF? Then use module ldif which automagically base64-encodes NON-ASCII values. Ciao, Michael. |
From: Zhang H. <zhb...@gm...> - 2009-06-05 23:50:09
|
Michael Ströder wrote: > Zhang Huangbin wrote: > >> Is there ny example to display jpegPhoto stored in LDAP as base64 format? >> > > Not sure what you really want to display and where. > > How about entry['jpegPhoto'][0].encode('base64') ? > > Or are you talking about LDIF? Then use module ldif which automagically > base64-encodes NON-ASCII values. > > Thanks Michael :) Just display the jpegPhoto on web page, not LDIF. :) I got encoded string after 'entry['jpegPhoto'][0].encode('base64') ', but how to convert it to a image file and use '<img> tag in HTML to display it? -- Best regards. Zhang Huangbin - Open Source Mail Server Solution for RHEL, CentOS, Debian, Ubuntu: + Homepage: http://code.google.com/p/iredmail/ + Forum: http://www.iredmail.org/forum/ |
From: Michael S. <mi...@st...> - 2009-06-06 10:35:26
|
Zhang Huangbin wrote: > Michael Ströder wrote: >> Zhang Huangbin wrote: >> >>> Is there ny example to display jpegPhoto stored in LDAP as base64 format? >>> >> Not sure what you really want to display and where. >> >> How about entry['jpegPhoto'][0].encode('base64') ? >> >> Or are you talking about LDIF? Then use module ldif which automagically >> base64-encodes NON-ASCII values. > > Just display the jpegPhoto on web page, not LDIF. :) > > I got encoded string after 'entry['jpegPhoto'][0].encode('base64') ', > but how to convert it to a image file and use '<img> tag in HTML to > display it? entry['jpegPhoto'][0] is the raw binary JPEG data. You can send this directly to the browser in the body of a HTTP response with MIME-type image/jpeg. This is kind of off-topic here since it's rather related to web app programming. So I'd recommend to ask in the forum related to the web app framework you're using. Ciao, Michael. |
From: Zhang H. <zhb...@gm...> - 2009-06-09 09:12:24
|
Zhang Huangbin wrote: > Zhang Huangbin wrote: >>> Not sure what you really want to display and where. >>> >>> How about entry['jpegPhoto'][0].encode('base64') ? > > Still confused what data type it stored in LDAP. > Already base64 encoded? > > Display entry['jpegPhoto'][0] directly, got error msg: > ---- > 'ascii' codec can't decode byte 0x89 in position 0: ordinal not in > range(128) > ---- > > How can i display it if i use 'content-type: image/jpeg' header? > Forget to say, it works in non-IE browsers like this: ---- <img src="data:image/jpeg;base64,**** output of entry['jpegPhoto'][0].encode('base64') here ****" /> ---- -- Best regards. Zhang Huangbin - Open Source Mail Server Solution for RHEL, CentOS, Debian, Ubuntu: + Homepage: http://code.google.com/p/iredmail/ + Forum: http://www.iredmail.org/forum/ |
From: Ryan L. <ry...@st...> - 2009-06-09 18:42:11
|
On Tue, Jun 09, 2009 at 05:14:33PM +0800, Zhang Huangbin wrote: > > How can i display it if i use 'content-type: image/jpeg' header? > > Forget to say, it works in non-IE browsers like this: > ---- > <img src="data:image/jpeg;base64,**** output of > entry['jpegPhoto'][0].encode('base64') here ****" /> > ---- You would have a tag such as <img src="jpegphoto.cgi?user=someone"> where jpegphoto.cgi is a CGI script that outputs "Content-type: image/jpeg" followed by the JPEG data. But that is an HTTP topic so you should probably consult a Python/CGI resource. Ryan |
From: Zhang H. <zhb...@gm...> - 2009-06-10 02:48:11
|
Ryan Lovett wrote: > You would have a tag such as <img src="jpegphoto.cgi?user=someone"> where > jpegphoto.cgi is a CGI script that outputs "Content-type: image/jpeg" > followed by the JPEG data. > > But that is an HTTP topic so you should probably consult a Python/CGI > resource. Solved, thanks all :) I use webpy framework, solved just like Ryan Lovett said. Related thread: http://groups.google.com/group/webpy/t/9f7fdff1c75f7e93 -- Best regards. Zhang Huangbin - Open Source Mail Server Solution for RHEL, CentOS, Debian, Ubuntu: + Homepage: http://code.google.com/p/iredmail/ + Forum: http://www.iredmail.org/forum/ |
From: Zhang H. <zhb...@gm...> - 2009-06-09 09:08:13
|
Zhang Huangbin wrote: >> Not sure what you really want to display and where. >> >> How about entry['jpegPhoto'][0].encode('base64') ? Still confused what data type it stored in LDAP. Already base64 encoded? Display entry['jpegPhoto'][0] directly, got error msg: ---- 'ascii' codec can't decode byte 0x89 in position 0: ordinal not in range(128) ---- How can i display it if i use 'content-type: image/jpeg' header? -- Best regards. Zhang Huangbin - Open Source Mail Server Solution for RHEL, CentOS, Debian, Ubuntu: + Homepage: http://code.google.com/p/iredmail/ + Forum: http://www.iredmail.org/forum/ |
From: Michael S. <mi...@st...> - 2009-06-09 19:37:51
|
Zhang Huangbin wrote: > Zhang Huangbin wrote: >>> Not sure what you really want to display and where. >>> >>> How about entry['jpegPhoto'][0].encode('base64') ? > > Still confused what data type it stored in LDAP. > Already base64 encoded? Please read my e-mails more carefully. As said in <4A2...@st...> it's the raw binary JPEG image data. > Display entry['jpegPhoto'][0] directly, got error msg: > ---- > 'ascii' codec can't decode byte 0x89 in position 0: ordinal not in > range(128) > ---- > > How can i display it if i use 'content-type: image/jpeg' header? Send the binary data directly. Don't try to (implicitly) convert entry['jpegPhoto'][0] to a Unicode object. You might want to learn a bit more about normal strings vs. Unicode objects, string coercion and how to interpret exceptions like the one above before going any further. Ciao, Michael. |