I'm using Spring for Android as a REST template for remote calls in Android app.

Currently working on uploading images to the server.

I came up with something like that:

public Picture uploadPicture(String accessToken, String fileToUpload) throws RestClientException {
    RestTemplate rest = new RestTemplate();
    FormHttpMessageConverter formConverter = new FormHttpMessageConverter();
    formConverter.setCharset(Charset.forName("UTF8"));
    CustomGsonHttpMessageConverter jsonConverter = new CustomGsonHttpMessageConverter();
    rest.getMessageConverters().add(formConverter);
    rest.getMessageConverters().add(jsonConverter);
    String uploadUri = AppConfig.ROOT_URL.concat(AppConfig.ADD_PHOTO);

    HashMap<String, Object> urlVariables = new HashMap<String, Object>();
    urlVariables.put("accessToken", accessToken);

    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setAccept(Collections.singletonList(MediaType.parseMediaType("application/json")));

    MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
    parts.add("picture", new FileSystemResource(fileToUpload));
    Picture response = rest.postForObject(uploadUri, parts, Picture.class, urlVariables);
    return response;
}

which works OK, but now I'd like to get progress updates from it.

Does anyone know if it's possible and how to do that?

Thanks in advance :)

share|improve this question
possible duplicate stackoverflow.com/questions/5294532/… – Marcin Wasiluk Jan 19 at 11:21
Not really - link posted by you is about post with built-in Apache HttpClient, not Spring for Android. I'd like to avoid using HttpClient if I can do it with Spring. – Damian Walczak Jan 19 at 11:43
Did you have any luck figuring this out? – Nick Mar 5 at 20:40

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.