2013-04-02 146 views
1

我是新手RoboSpice。 我正在嘗試上傳文件。但我得到這個錯誤:Robospice上傳文件問題

04-02 17:47:31.151: E//RequestProcessor.java:234(11021): org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [java.lang.String] and content type [text/html] 

。這是我的請求類:JacksonSpringAndroidSpiceService類:

public class UploadFileRequest extends SpringAndroidSpiceRequest<String>{ 
private static final String TAG = "UploadFileRequest"; 
private UploadRequestModel requestModel; 
private String link; 

public UploadFileRequest(UploadRequestModel model, String link) { 
    super(String.class); 
    requestModel = model; 
    this.link = link; 
} 

@Override 
public String loadDataFromNetwork() throws Exception {  


    MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>(); 
    parts.add("file1", new FileSystemResource(requestModel.getFile1())); 
    parts.add("file2", new FileSystemResource(requestModel.getFile1())); 
    return getRestTemplate().postForObject(link, parts, String.class); 


} 

} 

我一起工作。

非常感謝您的幫助。

+0

Oooh yeah ...即使有GET請求也會得到大量的這些...你知道我最終做了什麼嗎?不使用Spring模板...哦,並且對SpringAndroidSpiceService進行子分類。不,我不知道這到底是什麼錯誤。無知的框架... –

+0

是的。我看到它非常複雜。但我相信這會對我的項目有用:) – gZerone

回答

3

你可以從JacksonSpringAndroidSpiceServicesource code看到,它提供了一個轉換器僅application/json內容類型,通過MappingJacksonHttpMessageConverter類。

對於任何其他內容類型的Spring不知道如何處理它。

您可以輕鬆地添加通用傾角轉換器,其類別子類別爲JacksonSpringAndroidSpiceService或創建您自己的實現基於其源代碼。

+0

謝謝rciovati – gZerone

2

我有一個類似的問題,有以下

解決它取代

return getRestTemplate().postForObject(link, parts, String.class); 

RestTemplate restTemplate = getRestTemplate(); 
restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); 
return restTemplate.postForObject(link, parts, String.class); 

希望這有助於!