Python, ASP, ADO, and Image string/binary problems
shonn at shonn.com
Sat Mar 3 00:17:35 CET 2001
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 all
the COM functionallity added.
Here's what I'm trying to do:
<script runat="server" language="Python">
import os, sys
strSQL = "select * from [FILE] where FILE_Guid =
objConn = Server.CreateObject("ADODB.Connection")
objRS = Server.CreateObject("ADODB.Recordset")
bstrIn = objRS("FILE_File").value # returns a buffer, not a string
im = PIL.Image.open(StringIO.StringIO(bstrIn))
bstrOut = StringIO.StringIO()
Response.ContentType = 'text/html' #'image/jpeg'
If I do a Response.BinaryWrite(bstrIn) I get the image in the browser but if
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