Python, ASP, ADO, and Image string/binary problems
shonn at shonn.com
Wed Mar 7 06:54:24 CET 2001
It looks like I've figured out what part of the problem is but I don't have
a solution (well I do, but it's really ugly). Oh, and I'm new to python
coming from a VB background.
Okay, Python is processing the strings right (the tutorial didn't specify
that '\377' is octal not decimal.). The problem seems to be that when Python
passes strings through COM that they get translated to Unicode. This happens
for things like Response.BinaryWrite along with things like recordsets
(objRS = Server.CreateObject("ADODB.Recordset")). The result is that the
beginning of my jpg file looks like
Does anyone know how to handle this?
"Shonn Gilson" <shonn at shonn.com> wrote in message
news:ta0amgebq0sn0b at corp.supernews.com...
> Okay, here it goes.
> I have a site in ASP where I need to upload an image (already working) and
> then make a thumbnail of it. The image is stored in a MS SQL Server
> database, I'm using IIS5 (Win2k), and the python is Active State's with
> the COM functionallity added.
> Here's what I'm trying to do:
> <script runat="server" language="Python">
> import os, sys
> import PIL.Image
> import StringIO
> strSQL = "select * from [FILE] where FILE_Guid =
> objConn = Server.CreateObject("ADODB.Connection")
> objRS = Server.CreateObject("ADODB.Recordset")
> objConn.Open (connection_string)
> objRS.Open (strSQL,objConn,3,1)
> bstrIn = objRS("FILE_File").value # returns a buffer, not a string
> im = PIL.Image.open(StringIO.StringIO(bstrIn))
> im.thumbnail((128, 128))
> bstrOut = StringIO.StringIO()
> im.save(bstrOut, "JPEG",optimize=1,progressive=1)
> Response.ContentType = 'text/html' #'image/jpeg'
> Response.Write(" ")
> #Response.Write ('size')
> #Response.Write (`im.size`)
> If I do a Response.BinaryWrite(bstrIn) I get the image in the browser but
> I do Response.BinaryWrite(bstrOut.getvalue()) I get spaces between every
> character (I've seen this with unicode problems). It's not just an
> incompatibility with Response.BinaryWrite because I've written the results
> back to the database with the same results. It seems like it's a problem
> with how python deals with strings.
> Anyone have any ideas?
> Thanks in advance
More information about the Python-list