Announcement Announcement Module
Collapse
No announcement yet.
How can I send an image with Spring Framework for Android? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I send an image with Spring Framework for Android?

    I'm developing an Android 3.1 tablet application.

    This app is using SpringFramework to send JSON message to a server. Here is a working example which send a custom object to server:

    Code:
    	public static Boolean sendSignedEReport(String url, EReport eReport)
    	{
    		try
    		{
    			HttpHeaders requestHeaders = new HttpHeaders();
    			requestHeaders.setAccept(Collections.singletonList(new MediaType("application","json")));
    			HttpEntity<EReport> requestEntity = new HttpEntity<EReport>(eReport, requestHeaders);
    
    			GsonHttpMessageConverter messageConverter = new GsonHttpMessageConverter();
    			List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    			messageConverters.add(messageConverter);
    
    			HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    			requestFactory.setReadTimeout(60000);
    
    	        RestTemplate restTemplate = new RestTemplate(requestFactory);
    	        restTemplate.setMessageConverters(messageConverters);
    
    	        ResponseEntity<Boolean> responseEntity = 
                            restTemplate.exchange(url, HttpMethod.POST, requestEntity, Boolean.class);
    
    	        return responseEntity.getBody();
    		}
    		catch (Exception e)
    		{
    			e.printStackTrace();
    		}
    
    		return null;
    	}
    How can I modify this code to send an image?

  • #2
    The showcase app in the samples repository demonstrates how to send an image as multipart/formdata. Here is a link directly to the activity.

    https://github.com/SpringSource/spri...aActivity.java

    Comment


    • #3
      how do use but i dont no this answer plz tell me

      Comment


      • #4
        Originally posted by Roy Clarkson View Post
        The showcase app in the samples repository demonstrates how to send an image as multipart/formdata. Here is a link directly to the activity.

        https://github.com/SpringSource/spri...aActivity.java
        Thanks for your answer, but it doesn't work for me because WCF doesn't support multi-part messages.

        Comment

        Working...
        X