<html><div style='background-color:'><P>Thanks for the reply</P>
<P>I read first the one Danny sent me.</P>
<P>I'll try the code and let you know how it went</P>
<P>About the overwhelming of the machine, is a Dedicated Server so I don't think that would happen. The person in charge of the project told me that he needed a daemon to run under Linux to store in the database so he could take out the binary string into php and show it in a web site, so I think that's why he wants to store it in a database. Sorry I didn't comment this before it's just that I found&nbsp;out this yesterday :P</P>
<P>Thanks in advanced</P>
<P>Alberto&nbsp; </P>&gt;From: Matthew Dixon Cowles &lt;matt@mondoinfo.com&gt; &gt;Reply-To: help@python.org &gt;To: Alberto Troiano &lt;albertito_g@hotmail.com&gt; &gt;CC: help@python.org &gt;Subject: Re: [Python-Help] Support with Image &gt;Date: Sat, 9 Apr 2005 13:52:52 -0500 (CDT) &gt; &gt;Dear Alberto, &gt; &gt; &gt; but now I don't know how to retrieve the image &gt; &gt; &gt; outFile = StringIO() &gt; &gt; im.save(outFile, "JPEG") &gt; &gt; &gt; cursor.execute("insert into image values('',%s)",outfile) &gt; &gt;It would surprise me very much if that worked correctly. Have you &gt;checked to see what's stored in your database after you've done that? &gt; &gt;What Danny said was: &gt; &gt; Here, we use StringIO to use an in-memory file-like object: &gt; &gt; http://www.python.org/doc/lib/module-StringIO.html &gt; &gt; and we can use getvalue() to get at the binary bytes that you'll 
&gt; probably want to store into your database. &gt; &gt;Depending on just how you're getting the data for your images, you &gt;may want to go through a StringIO object or you may be able to just &gt;work with the bytes that are in the file. &gt; &gt;But it's pretty common that it's not a very good idea to store image &gt;data in a database. If your images are pretty small and your database &gt;has a "BLOB" (binary large object) type, you may have some luck. If &gt;either of those isn't the case, the overhead of getting your images &gt;into and out of the database may overwhelm your machine. You might &gt;want to consider storing your image files semi-randomly in a &gt;directory hierarchy and recording in your database only the path to &gt;the file. If you have only a few hundred or a few thousand images, a &gt;single directory may be sufficient. If you have many more of them &gt;than 
that, you may want to split them up according to some rule that &gt;results in approximately equal numbers going in different directories. &gt; &gt; &gt; cursor.execute("select * from image") &gt; &gt; res=cursor.fetchall() &gt; &gt; &gt; &gt; Now I have the binary string in res[1] but when I try to open it it &gt; &gt; gives me an error &gt; &gt;Here's where you may want a StringIO object. If whatever you're &gt;giving the image to expects it in a file rather than a string, you &gt;could do somwthing like: &gt; &gt; &gt;&gt;&gt; s=StringIO.StringIO() &gt; &gt;&gt;&gt; s.write(res[1]) &gt; &gt;&gt;&gt; s.seek(0) &gt; &gt;and then give the variable s to whatever wants to read the file. &gt; &gt;Regards, &gt;Matt &gt; </div></html>