From: Kaspar Schiess Date: 2005-01-06T21:31:53+09:00 Subject: Re: Image decompression, eruby (In response to news:a48d774d050105150167c9244@mail.gmail.com by Belorion) > Since the raw image encoding contains characters MySQL doesn't like > when doing an INSERT, I encoded the image using Base64.encode64(). I recommend storing the binary data in BLOB's or whatever that data type is called with mysql. Then you can insert data by doing insert into mytable (blobcol) values (?) The question mark is a placeholder for the data. You can bind your binary data to it by calling DBI#execute as follows: dbh.execute( stmt, data ) Note that there are some RDBMS' out there that disallow BLOB inserts. If this is the case, you need to first insert all non-blob columns and then go back and UPDATE your table's blob columns (selecting the id's you have just inserted). This data then comes back from a SELECT as normal binary data which is exactly (and without detour) your image. It can be sent to the browser by the following code (untested): # image contained in +data+ require 'cgi' c = CGI.new c.print c.header( 'type' => 'image/gif', 'length' => data.length ) STDOUT.binmode if PLATFORM =~ /32/ c.print data The binmode part is UGLY, but there seems to be no other way to do this. happy hacking ! kaspar nb: This is a part of the DBI manual: execute( stmt, *bindvars ) {|statement_handle| aBlock} Immediately executes the SQL statement stmt after binding the values in bindvars to the placeholders in the statement. kaspar hand manufactured code - www.tua.ch/ruby