def add_multipart_data(req, params)
      crlf = "\r\n"
      boundary = Time.now.to_i.to_s(16)
      req["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
      body = ""
      params.each do |key,value|
        esc_key = CGI.escape(key.to_s)
        body << "--#{boundary}#{crlf}"
        if value.respond_to?(:read)
          body << "Content-Disposition: form-data; name=\"#{esc_key}\"; filename=\"#{File.basename(value.path)}\"#{crlf}"
          body << "Content-Type: image/jpeg#{crlf*2}"
          body << open(value.path, "rb") {|io| io.read}
        else
          body << "Content-Disposition: form-data; name=\"#{esc_key}\"#{crlf*2}#{value}"
        end
        body << crlf
      end
      body << "--#{boundary}--#{crlf*2}"
      req.body = body
      req["Content-Length"] = req.body.size
    end
def add_multipart_data(req, params)
      crlf = "\r\n"
      boundary = Time.now.to_i.to_s(16)
      req["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
      body = ""
      params.each do |key,value|
        esc_key = CGI.escape(key.to_s)
        body << "--#{boundary}#{crlf}"
        if value.respond_to?(:read)
          body << "Content-Disposition: form-data; name=\"#{esc_key}\"; filename=\"#{File.basename(value.path)}\"#{crlf}"
          body << "Content-Type: image/jpeg#{crlf*2}"
          body << open(value.path, "rb") {|io| io.read}
        else
          body << "Content-Disposition: form-data; name=\"#{esc_key}\"#{crlf*2}#{value}"
        end
        body << crlf
      end
      body << "--#{boundary}--#{crlf*2}"
      req.body = body
      req["Content-Length"] = req.body.size
    end
Encodes the request as multipart