I'm trying to test multipart post with:
Rho::AsyncHttp.upload_file(
:url => 'http://my_uri_here/',
:multipart => [
{
:filename => File.join(Rho::RhoApplication::get_base_app_path(), 'rhoconfig.txt'),
:name => "model[file]",
},
{
:body => "upload test",
:name => "model[text]", # optional, 'blob' used as default
#:content_type => "plain/text" # optional, 'application/x-www-form-urlencoded' used as default
}])
and on backend server(running rails 3) I get error:
NoMethodError (undefined method `rewind' for "upload test":String)
POST /account/1/bills HTTP/1.1
Host: 192.168.0.101:3000
Accept: */*
Accept-Encoding: deflate, gzip
Connection: Keep-Alive
User-Agent: Mozilla-5.0 (ANDROID; generic; 2.2)
Content-Length: 860
Content-Type: multipart/form-data; boundary=----------------------------11a1a536b694
------------------------------11a1a536b694
Content-Disposition: form-data; name="bill[file]"; filename="rhoconfig.txt"
Content-Type: application/octet-stream
Content-Length: 449
# syncserver='http://rhodes-samples-server.heroku.com/application'
...
------------------------------11a1a536b694
Content-Disposition: form-data; name="bill[text]"
Content-Type: application/x-www-form-urlencoded
Content-Length: 11
upload test
------------------------------11a1a536b694--
curl --trace-ascii out -F "bill[file]=@README" -F "bill[text]=test" http://localhost:3000/account/1/bills
POST /account/1/bills HTTP/1.1
User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.1
9.7 OpenSSL/0.9.8l zlib/1.2.3
Host: localhost:3000
Accept: */*
Content-Length: 9437
Expect: 100-continue
Content-Type: multipart/form-data; boundary=--------------------
--------c4c4ba95406f
------------------------------c4c4ba95406f
Content-Disposition: form-data; name="bill[file]"; filename="README"
Content-Type: application/octet-stream
file content here....
------------------------------c4c4ba95406f
Content-Disposition: form-data; name="bill[text]"
upload test
------------------------------c4c4ba95406f--
Content-Type header should not be present, when multipart body is set ( name[text]=upload test )
That's what curl's request headers say, and what Rack::Utils.process_multipart expects