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
source to share
No one has answered this question yet
Check out similar questions: