Spring for Android, file upload / download

I am starting to use Spring framework in my android project to upload / download file from server. My problem is how to update progress on upload / download? Does anyone have any idea?

My code for uploading a file using Spring:

public String editPersonalAvatar(UserProfile user, String url) {
        String result = "";
        File file = new File(user.getAvatar());
        MultiValueMap<String, Object> mapWithFile;
        mapWithFile = new LinkedMultiValueMap<String, Object>();
        mapWithFile.add("file", new FileSystemResource(file));
        RestTemplate restTemplate = new RestTemplateHelper().createRestTemplate(new FormHttpMessageConverter(),
                                                                   new StringHttpMessageConverter());
        result = restTemplate.postForObject(url, mapWithFile, String.class);

        return result;
    }

      

Another problem: I am requesting an HTTPPOST to the server and I am getting large JSON (example 2MB). Can I calculate the download percentage?

Sample code:

public static String confirmGetFile(String url, String username,String id) throws Exception {

        MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
                map.add("user", username);

        map.add("id", id);
        RestTemplate restTemplate = new RestTemplateHelper().createRestTemplate(new FormHttpMessageConverter(),
                                                                                new StringHttpMessageConverter());
        String result = restTemplate.postForObject(url, map, String.class);
        Log.d("***RESULT CONFIRM", result);
        return result;
    }

      

+3
spring android android-progressbar


source to share


No one has answered this question yet

Check out similar questions:

3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to persist android activity state by persisting instance state?
2097
Is there a way to run Python on Android?
1873
What's the difference between @Component, @Repository and @Service annotations in Spring?
1858
"Debug certificate expired" error in Android Eclipse plugins
1844
What is "Context" on Android?
964
Download file from Android and show progress in ProgressDialog



All Articles
Loading...
X
Show
Funny
Dev
Pics