How to send multpart/form-data file along with other form parameters in ruby net/http? -


i want upload file using post method having content type of multipart/form-data along other form parameters. have tried code i'm getting error.

require 'net/http/post/multipart'  url = uri.parse('https:action/upload-v1/file') file.open("rough.txt") |text|   req = net::http::post::multipart.new url.path,     "file" => uploadio.new(text, "text/plain", "rough.txt")      req.basic_auth 'nikhil', 'lee'      req.verify_mode = openssl::ssl::verify_none     req.use_ssl = true     req.set_form_data('deviceid' => '2366', 'checksum' => '132654798', 'filesize' => '1260', 'filetype' => 'configuration', 'compressiontype' => 'z')   res = net::http.start(url.host, url.port) |http|     response = http.request(req)     puts response.body    end end 

error:

c:\ruby193>ruby testmultipart.rb testmultipart.rb:10:in `block in <main>': undefined method `verify_mode=' #<net::http::post::multipart post> (nomethoderror)         testmultipart.rb:4:in `open'         testmultipart.rb:4:in `<main>' 

you can try this.

require 'net/http/post/multipart'  url = uri.parse('https:action/upload-v1/file') file.open("rough.txt") |text|     "file" => uploadio.new(text, "text/plain", "rough.txt")     req = net::http::post::multipart.new url.path     req.basic_auth 'nikhil', 'lee'     req.set_form_data('deviceid' => '2366', 'checksum' => '132654798', 'filesize' => '1260', 'filetype' => 'configuration', 'compressiontype' => 'z')     res = net::http.start(url.host, url.port, :use_ssl => url.scheme == 'https') |http|        http.verify_mode = openssl::ssl::verify_none        response = http.request(req)        puts response.body   end end 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -