Class: Net::HTTP::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/multipart.rb

Instance Method Summary collapse

Instance Method Details

#multipart_params=(params = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/multipart.rb', line 8

def multipart_params=(params = {})
  boundary_token = [Array.new(8) {rand(256)}].join
  self.content_type = "multipart/form-data; boundary=#{boundary_token}"
  boundary_marker = "--#{boundary_token}\r\n"
  self.body = params.map { |param_name, param_value|
    boundary_marker + case param_value
    when String
      text_to_multipart(param_name, param_value)
    when File
      file_to_multipart(param_name, param_value)
    end
  }.join('') + "--#{boundary_token}--\r\n"
end