16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/multipart.rb', line 16
def multipart_params=(param_hash={})
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 = param_hash.map { |param_name, param_value|
boundary_marker + text_to_multipart(param_name, param_hash.delete(param_name).to_s) unless param_value.respond_to?(:read)
}.join('')
self.body += param_hash.map { |param_name, param_value|
boundary_marker + file_to_multipart(param_name, param_value)
}.join('')
self.body += "--#{boundary_token}--\r\n"
end
|