Uploading a file with net/HTTP

puts Net::HTTP.post_form(URI.parse('http://example.com/upload.php'),
   { 'username' => 'foo', 'password' => 'bar', 'Filedata' => File.new('way_home.wmv', 'r').read + '\r\n' })

the result is a pipe error ...

irb(main):015:1* { 'username' => 'h-art', 'password' => 'm3di4', 'Filedata' => File.new('way_home.wmv', 'r').read + '\r\n' })
Errno::EPIPE: Broken pipe
         from /opt/local/lib/ruby/1.8/net/protocol.rb:175:in `write'
         from /opt/local/lib/ruby/1.8/net/protocol.rb:175:in `write0'
         from /opt/local/lib/ruby/1.8/net/protocol.rb:151:in `write'
         from /opt/local/lib/ruby/1.8/net/protocol.rb:166:in `writing'
         from /opt/local/lib/ruby/1.8/net/protocol.rb:150:in `write'
         from /opt/local/lib/ruby/1.8/net/http.rb:1537:in `send_request_with_body'
         from /opt/local/lib/ruby/1.8/net/http.rb:1522:in `exec'
         from /opt/local/lib/ruby/1.8/net/http.rb:1045:in `request'
         from /opt/local/lib/ruby/1.8/net/http.rb:405:in `post_form'
         from /opt/local/lib/ruby/1.8/net/http.rb:543:in `start'
         from /opt/local/lib/ruby/1.8/net/http.rb:404:in `post_form'
         from (irb):14
         from /opt/local/lib/ruby/1.8/net/http.rb:856

How can I solve this ?

   ngw

···

--
Nicholas Wieland
nicholas.wieland@gmail.com

Yeah, unfortunately Net::HTTP doesn't provide a pretty way to do file
uploads. Here are some (not pretty) workarounds:
http://kfahlgren.com/blog/2006/11/01/multipart-post-in-ruby-2/

HTH,
Keith

···

On 3/23/07, Nicholas Wieland <nicholas.wieland@gmail.com> wrote:

puts Net::HTTP.post_form(URI.parse('http://example.com/upload.php&#39;\),
   { 'username' => 'foo', 'password' => 'bar', 'Filedata' => File.new
('way_home.wmv', 'r').read + '\r\n' })