5

I need to send a large file from Android Tablet to a server.

So now I'm using Android Annotation to do it, but now I get OutOfMemory Exception becuase my file is bigger than 35MB. I searched and I undesrstand that if I use FileOutputStream with connection I can avoid that Exception.

But how can I get output stream from my connection using @Rest AndroidAnnotation Class?

This is my code:

@Rest(converters = {FormHttpMessageConverter.class, MappingJackson2HttpMessageConverter.class}
/*, interceptors=MyClientHttpRequestInterceptor.class*/)
public interface DbRestClient  extends RestClientErrorHandling{

    void setRootUrl(String rootUrl);

    String getRootUrl();

    void setRestTemplate(RestTemplate restTemplate);

    RestTemplate getRestTemplate();

    @Post("dbSynk/postNew")
    Integer postDb(MultiValueMap file);
}

And into my @EService:

@RestService DbRestClient dbRestClient;

...

dbRestClient.postDb(file)

Have you any ideas?

PaolaG
  • 814
  • 1
  • 11
  • 27
  • Why you sending 35MB file to server ? could you please explain scenario.What kind of large file ? – IshRoid Aug 11 '15 at 12:05
  • @IshArt It's a .db file, I want to transfer for Backup it on server. – PaolaG Aug 11 '15 at 12:14
  • If this is databae file then upload it by query, one or five rows at once,,or if not then increase connection time,, – IshRoid Aug 11 '15 at 12:14
  • @IshArt I don't want to copy the row in another db. Is a local DB, that for backup (an user broke the tablet under a machine) I want to transfer every day on my server. – PaolaG Aug 11 '15 at 12:18
  • http://stackoverflow.com/questions/9630430/upload-large-file-in-android-without-outofmemory-error – gipinani Aug 17 '15 at 19:53

1 Answers1

0

Use @Part and FormHttpMessageConverter.

The commonly used MappingJackson2HttpMessageConverter loads the entire file to memory, while conveting the file to JSON. Using FormHttpMessageConverter it will stream the file content instead of loading it to memory.

Italo Borssatto
  • 15,044
  • 7
  • 62
  • 88