def set_multipart_data(files_params,
other_params={},
boundary1="paranguaricutirimirruaru0xdeadbeef",
boundary2="paranguaricutirimirruaru0x20132")
self.content_type = "multipart/form-data; boundary=\"#{boundary1}\""
tmp = StringIO.new('r+b')
other_params.each do |key,val|
tmp.write "--#{boundary1}\r\n"
tmp.write "content-disposition: form-data; name=\"#{key}\"\r\n"
tmp.write "\r\n"
tmp.write "#{val}\r\n"
end
files_params.each do |name, file|
tmp.write "\r\n--#{boundary1}\r\n"
tmp.write "content-disposition: form-data; name=\"#{name}\""
if not file.is_a? Enumerable
if file.filename
tmp.write "; filename=\"#{file.filename}\"\r\n"
else
tmp.write "\r\n"
end
tmp.write "Content-Type: #{file.mimetype}\r\n"
tmp.write "Content-Transfer-Encoding: binary\r\n"
tmp.write "\r\n"
tmp.write(file.read())
file.maybeclose
else
tmp.write "\r\n"
tmp.write "Content-Type: multipart/mixed;"
tmp.write " boundary=\"#{boundary2}\"\r\n"
file.each do |f|
tmp.write "\r\n--#{boundary2}\r\n"
tmp.write "Content-disposition: attachment"
if f.filename
tmp.write "; filename=\"#{f.filename}\"\r\n"
else
tmp.write "\r\n"
end
tmp.write "Content-Type: #{f.mimetype}\r\n"
tmp.write "Content-Transfer-Encoding: binary\r\n"
tmp.write "\r\n"
tmp.write(f.read())
f.maybeclose
end
tmp.write "\r\n--#{boundary2}--\r\n"
end
end
tmp.write "--#{boundary1}--\r\n"
tmp.flush
self.content_length = tmp.size
self.body_stream = tmp
self.body_stream.seek(0)
nil
end