From: Brian Candler Date: 2003-04-08T17:00:10+09:00 Subject: Re: sending a file via http On Tue, Apr 08, 2003 at 02:32:35PM +0900, Andrew wrote: > I'm trying to send a file using http in a ruby script of mine. A CGI, presumably? > This is what I have so far... > .... > file = File.open("data.zip") > puts "Content-type: application/x-zip-compressed\n" > puts "Content-length: "+File.size("album.zip").to_s+"\n\n" > > ok, now what? How do I send the file data? You should be OK with: print File.read("album.zip") Or slightly more efficient, File.open("album.zip") do |f| print f.read end because it closes the file immediately, rather than waiting until garbage-collection time. If running as a CGI you shouldn't need to generate a Content-length: header, just let your webserver deal with it. It can use chunked transfer encoding if the file is large. Regards, Brian.