title: Redmine/Rails - Undefined method while sending POST data
body: <p>Redmine allows the user to add files to a document manually, my goal is to create a method that does that automatically.</p>
  
  <p>I've added a file manually while sniffing with Wireshark to get the POST requests that I want to recreate in my method to help me a little bit (I can't post some screenshots (if needed), my reputation is too low).</p>
  
  <p>Redmine official website offers informations to how attach files here: <a href="http://www.redmine.org/projects/redmine/wiki/Rest_api#Attaching-files" rel="nofollow">http://www.redmine.org/projects/redmine/wiki/Rest_api#Attaching-files</a></p>
  
  <p>So after hours browsing the Web and particulary StackOverflow and <a href="https://coderwall.com/p/c-mu-a" rel="nofollow">here</a>, I finally wrote a method:</p>
  
  <pre><code>require 'net/http'
  require 'uri'
  
  uri = URI.parse("/uploads.js")
  http = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =&gt; 'application/octet-stream'})
  request.body = File.new("/home/testFile.txt", 'rb')
  @response = http.request(request)
  </code></pre>
  
  <p>As explained on the Redmine website I specified the content-type in the header and I added the file in the body request.</p>
  
  <p>Now I get the following error:</p>
  
  <pre><code>NoMethodError (undefined method `+' for nil:NilClass):
  /usr/local/lib/ruby/1.9.1/net/http.rb:1404:in `addr_port'
  /usr/local/lib/ruby/1.9.1/net/http.rb:1339:in `begin_transport'
  /usr/local/lib/ruby/1.9.1/net/http.rb:1315:in `transport_request'
  /usr/local/lib/ruby/1.9.1/net/http.rb:1293:in `request'
  rest-client (1.6.7) lib/restclient/net_http_ext.rb:51:in `request'
  /usr/local/lib/ruby/1.9.1/net/http.rb:1286:in `block in request'
  /usr/local/lib/ruby/1.9.1/net/http.rb:745:in `start'
  /usr/local/lib/ruby/1.9.1/net/http.rb:1284:in `request'
  rest-client (1.6.7) lib/restclient/net_http_ext.rb:51:in `request'
  plugins/redmine_reddrop/app/controllers/projectusers_controller.rb:360:in `addFile'
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I updated my uri with an absolute URL like this:</p>
  
  <pre><code>uri = URI.parse("http://&lt;server_IP_address&gt;:3000/uploads.js")
  </code></pre>
  
  <p>And now I'm getting the following error:</p>
  
  <pre><code>NoMethodError (undefined method `bytesize' for #&lt;File:/home/testFile.txt&gt;):
  </code></pre>
  
  <p>Do you see any error in my method or do you have any idea where does this error come from?</p>
  
  <p>Note: I'm using rails 3.2.16 and Ruby 1.9.3-p392</p>