From: Belorion Date: 2005-01-07T00:37:23+09:00 Subject: Re: Image decompression, eruby > Shouldn't that be cgi.header("type"=>"image/jpg") ? Yes, it should, and it is in my code ;) > Just a guess: check for blanks/new lines around the <%= data %>. Nope, can't find any blank lines.... > The other possibility is to add a header "Content-Transfer-Encoding: base64" > and send the base64 encoded photo directly. Good idea. Gave it a shot, but couldn't get it to work. Same errors. > 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 ) > I hadn't seen that before. I gave it a shot. Seems to work fine for getting the browser to display an image. I take that back, dbh.do( stmt, data ) works fine, I get an error with dbh.execute. However, the image is coming back with glaring errors. After further investigation it appears that the raw data in the MySQL table has issues, though I can't tell if it's from the way the data is inserted, or if is corrupted from the actual upload. So my first question regarding displaying the image via eruby in my browser has been answered (thanks!), but maybe someone has an idea as to why my data is being corrupted (the image comes back with a ton of artifacts, especially with strange bars of color). The way I am uploading my file is derived from a script I found at http://www.zytrax.com/tech/lang/ruby/#upload. Specifically, my HTML for uploading looks like:
> And my upload specific ruby in attach.rhtml looks like: fromfile = cgi.params['myfile'].first fromfile.binmode # Tried both with and without this line dbh.do( "INSERT INTO attachments VALUES( ? )", [ index, fromfile.original_filename, fromfile.read] ) So, somewhere in that process the data gets corrupted, and the image comes out half garbled. Any ideas? Plain text files, which are handled using the exact same script, come out just fine.