[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: sending a file via http
From:       "Andrew" <nospam123 () anon ! com>
Date:       2003-04-08 23:37:02
[Download RAW message or body]

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" <B.Candler@pobox.com> 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.
>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic