String Literal to Blob
Steve Holden
steve at holdenweb.com
Wed Apr 9 10:24:16 EDT 2008
Victor Subervi wrote:
> On Wed, Apr 9, 2008 at 1:14 AM, Gabriel Genellina
> <gagsl-py2 at yahoo.com.ar <mailto: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
>
Now all you have to do is what I told you in the first place, which is
to remove the print statements before and after "print content".
You are NOT generating HTML, you are generating a JPEG image.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list