String Literal to Blob

Victor Subervi victorsubervi at gmail.com
Wed Apr 9 16:15:52 CEST 2008


On Wed, Apr 9, 2008 at 1:14 AM, Gabriel Genellina <gagsl-py2 at yahoo.com.ar>
wrote:

> > Thanks. I apparently am printing some holder for the image. I stripped
> > out
> > most of it with this
> > content[0][0]
> > but then I am left with this:
> >
> > array('c', '\xff\xd8\xff\xe0\\0\x10JFI...)
> > How do I extract an image from that?
>
> print content.tostring()


Now *that* gave me something that *looks* a lot more like an image from a
programmers perspective, but still no image...
ÿØÿàJFIF...
Actually, it does not copy and paste well, but you can see it for the moment
here:
http://livestocksling.com/test/python/Shop/display_es2.py
So, how do I convert *that* to a real live image?


> Or perhaps, replace that line with content.tofile(sys.stdout)


Printed nothing.


> >> >   print 'Content-Type: image/jpeg\r\n'
> >> >   print '<html><body>\n'
> >> >   print content
> >> >   print '</body><html>\n'
> >> >   cursor.close()
> >> >
> >> > test()
>
> >> > The commented out line gives me a leading less than sign...and that´s
> >> > it. What do?
>
> Try to understand now *why* you got a single character with your previous
> code.


No clue  :/

BTW, for purposes of documentation, it appears that, when sending the form
with the image to the script that processes the form, the following is
inadvisable:

  form = cgi.FieldStorage()
  pic1 = form.getfirst('pic1', '')

This appears to work better:

  form = cgi.FieldStorage()
  imgfile=open("pixel.gif",'rb')
  pixel = imgfile.read()
  pic1 = form.getfirst('pic1', pixel)

because it gives a binary default. The string appears to screw things up.
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080409/b00b3f55/attachment.html>


More information about the Python-list mailing list