我想通过 Android 应用程序将文件 + 字符串上传到我的 Rails 应用程序。但是在 rails 中使用分段上传时,我总是会遇到一个奇怪的错误。
我在客户端使用 Apache HttpClient 4.1.1 + httpMime Lib 4.1.1,在服务器端使用 Rails 3.0.10。
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);
这将是 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):
我找不到任何解决方案 - 谁有提示?
谢谢, 马丁
最佳答案
像这样创建您的多部分实体:
MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );
它会起作用。
关于java - 分段上传不适用于 android + rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7089590/