Search code examples
androidrobospice

Robospice upload files issue


I am newbie with RoboSpice. I am trying to upload files. But I got this error :

 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]

.This is my request class :

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);


}

}

I am working with : JacksonSpringAndroidSpiceService class.

Thank you very much for any help.


Solution

  • As you can see from the JacksonSpringAndroidSpiceService source code, it provides a converter for application/json content-type only, through the MappingJacksonHttpMessageConverter class.

    For any other content-type Spring doesn't know how to handle it.

    You can easily add a general pourpose converter with the StringHttpMessageConverter class subclassing JacksonSpringAndroidSpiceService or creating your own implementation base on its source code.