From: Andrew Date: 2003-04-09T08:37:02+09:00 Subject: Re: sending a file via http Yes, this is using CGI. Your code seems to do almost what I want, but it reads a few (10-20?) bytes and then stops. Is there something in the zip file that 'read' would interpret as an end of file maybe and cause it to stop? Thanks, Andrew "Brian Candler" wrote in message news:20030408080007.GA17485@uk.tiscali.com... > 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. >