I\'m developing a remote backup app, and Sometimes I need upload big files as for example 15 MB, I have tested in some phones I get an out of memory error
Is there a
Add
conn.setFixedLengthStreamingMode(sourceFile.length());
below:
conn = (HttpURLConnection) url.openConnection();
You should use either the setChunkedStreamingMode()
or setFixedLengthStreamingMode()
methods of the HttpURLConnection. This will prevent the buffering of your data in memory and exhausting it.
Relevant quote from the documentation:
For best performance, you should call either setFixedLengthStreamingMode(int) when the body length is known in advance, or setChunkedStreamingMode(int) when it is not. Otherwise HttpURLConnection will be forced to buffer the complete request body in memory before it is transmitted, wasting (and possibly exhausting) heap and increasing latency.
More here: http://developer.android.com/reference/java/net/HttpURLConnection.html