2011-08-17 26 views
4

我想通過Android應用程序上傳文件+字符串到我的Rails應用程序。但是在rails中使用分段上傳時,我總會遇到一個奇怪的錯誤。mulitpart上傳不能使用android + rails

我在客戶端使用Apache HttpClient 4.1.1 + httpMime Lib 4.1.1,在Serverside上使用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); 

這將是軌道錯誤行:

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

我cannout找到這個任何解決方案 - 任何人有一個提示嗎?

感謝, 馬丁

回答

4

創建多部分實體是這樣的:

MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 

它去上班。

+0

謝謝!那讓我頭疼:) – magegu

+0

如果我可以的話我會+5 – Maragues