开发者

mulitpart upload not working with android + rails

开发者 https://www.devze.com 2023-03-28 11:20 出处:网络
i want to upload a file + String to my Rails app via an Android App.But I\'ll always get a weird error, when using the multipart upload in rails.

i want to upload a file + String to my Rails app via an Android App. But I'll always get a weird error, when using the multipart upload in rails.

I'm using Apache HttpClient 4.1.1 + httpMime Lib 4.1.1 on 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 would be the error line in 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/a开发者_C百科ctionpack-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 cannout find any solution for this - anyone have a hint?

thanks, Martin


Create your Multipart entity like this:

MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );

And it's going to work.

0

精彩评论

暂无评论...
验证码 换一张
取 消