多部分上传不适用于 android +导轨
我想通过 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):
我无法找到任何解决方案 - 有人有提示吗?
谢谢, 马丁
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/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 cannout find any solution for this - anyone have a hint?
thanks,
Martin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样创建您的多部分实体:
它会起作用。
Create your Multipart entity like this:
And it's going to work.