Announcement Announcement Module
No announcement yet.
Upload Multipart JSON and File combination Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Upload Multipart JSON and File combination

    Good day,

    I am currently using RoboSpice with Spring Android framework to perform REST calls. I would like to perfrorm a multi-part form post, with a combination of JSON and files. I build up my REST template and add the necessary converters:

    public RestTemplate createRestTemplate() { 
            RestTemplate restTemplate = new RestTemplate(); 
            restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
            restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
            restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
            return restTemplate;
    I then perform the post:

    public boolean loadDataFromNetwork() throws IOException {
    		String url = context.getString(R.string.service_url) + "Registration";
    		HttpHeaders requestHeaders = new HttpHeaders();				
                    MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>(); 
    		map.add("request", registration); 
    		for (FicaDocument document : registration.documents)
    			map.add(document.documentPath, new FileSystemResource(document.documentPath)); 
    		HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<MultiValueMap<String, Object>>(map, requestHeaders);
    		RestTemplate restTemplate = getRestTemplate(); 
    		ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, requestEntity, String.class); 		
    		return true;  
    I now get the following error:

    05-27 09:53:22.380: E// 09:53:22.384 pool-2-thread-1 An exception occured during request network execution :Could not write request: no suitable HttpMessageConverter found for request type [com.flash.flashfica.types.FicaRegistration]

    The registration type looks as follows (using Jackson here):

    public class FicaRegistration implements Serializable {					
    	public long ficaRegistrationId; 
    	public String name; 
    	public String surname; 
    	public ArrayList<FicaDocument> documents;
    I can confirm that the call works fine when I do not use multi-part and just post the registration object in isolation. The JSON in this instance is created perfectly. In fact, I use the same pattern all over my application.

    Essentially, I need to perform a form post that combines JSON and Files in a single call.


  • #2
    Nice example you given here is looking perfect i am also using this methods sometimes, it's good technique. I dont know why occur this type of error.?