From: Belorion Date: 2005-01-07T01:47:05+09:00 Subject: Re: Image decompression, eruby I feel dumb. the Base64 was one of the first approaches I used. I just tried it again and it worked. I'm not sure what I am doing right this time that I was doing wrong the last... but it works now! Thanks everyone for the help! And, for anyone searching Ruby talk for a binary file upload solution using MySQL, here ya go: HTML:
In attach.rhtml, the relavent code for insertion into MySQL is: require 'cgi' require 'base64' require 'dbi' require 'stringio' # not sure if you need this myfile = cgi.params['myfile'].first dbh = DBI.connect( "DBI:Mysql:userdb", "user", "psswd" ) dbh.do( "INSERT INTO table VALUES( ? )", Base64.encode64(myfile.read) ] ) dbh.disconnect And then, to view the file using eruby: <% require 'cgi' require 'dbi' require 'base64' cgi = CGI.new dbh = DBI.connect( "DBI:Mysql:userdb", "user", "psswd" ) sth = dbh.prepare( " (statement to select out your data) " sth.execute data = sth.fetch[0] # assuming your binary data is the only thing returned print cgi.header("type"=>"image/jpg", "length"=>data.length) cgi.print Base64.decode64(data) %>