Downloading mulitpart does not work with android + rails

I want to upload a + String file to my Rails application through an Android application. But I always get a weird error when using multi-page loading in rails.

I am using Apache HttpClient 4.1.1 + httpMime Lib 4.1.1 on the client side and Rails 3.0.10 on Serverside.

CountingMultipartEntity mpEntity = new CountingMultipartEntity(this); File file = new File(getRealPathFromURI(Uri.parse(local_uri))); ContentBody cbFile = new FileBody(file, "image/jpeg"); mpEntity.addPart("artifact[binary_payload]", cbFile); mpEntity.addPart("artifact[description]", new StringBody("test", Charset.forName("UTF-8"))); HttpPost post = new HttpPost(url); post.setEntity(mpEntity); HttpResponse response = mHttpClient.execute(post); 

this will be the error line in the rails:

 Error during failsafe response: ActionView::Template::Error /Users/magu/.rvm/gems/ ruby-1.9.2-p136@ssp /gems/activesupport-3.0.10/lib/active_support/whiny_nil.rb:48:in `method_missing' /Users/magu/.rvm/gems/ ruby-1.9.2-p136@ssp /gems/actionpack-3.0.10/lib/action_dispatch/http/parameters.rb:10:in `parameters' ... /Users/magu/.rvm/gems/ ruby-1.9.2-p136@ssp / 09:51:55 NoMethodError (undefined method `rewind' for "test":String): 

I can't find a solution for this - who has a clue?

thanks Martin

+4
source share
1 answer

Create your multi-page object as follows:

 MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE ); 

And he will work.

+4
source

All Articles