2013-04-02 141 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); 

希望这有助于!