Problem description
Trying to upload a big base64 string using an HTTPClient request fails due to memory error. The string has been generated using the code below, in order to avoid the memory error while encoding (see TIMOB-15594).
Code used to encode
var stream = Ti.Filesystem.openStream(Ti.Filesystem.MODE_READ, SOME_FILE);
var buffer = Ti.createBuffer({
length: 300 // must be multiple of 3
});
var converted = "";
var len = 0;
while((len = stream.read(buffer)) != -1) {
buffer.length = len;
converted += Ti.Utils.base64encode(buffer.toBlob());
buffer.clear();
}
Error log while sending the base64 string with HTTPClient
11-21 11:19:16.986: E/dalvikvm-heap(30261): Out of memory on a 4782893-byte allocation.
11-21 11:19:16.986: I/dalvikvm(30261): "TiHttpClient-2" prio=1 tid=16 RUNNABLE
11-21 11:19:16.986: I/dalvikvm(30261): | group="main" sCount=0 dsCount=0 obj=0x43a379a0 self=0x5e64a230
11-21 11:19:16.986: I/dalvikvm(30261): | sysTid=2355 nice=19 sched=0/0 cgrp=apps/bg_non_interactive handle=1596774976
11-21 11:19:16.991: I/dalvikvm(30261): | schedstat=( 215870373 20054584 25 ) utm=21 stm=0 core=3
11-21 11:19:16.991: I/dalvikvm(30261): at java.nio.charset.Charsets.toUtf8Bytes(Native Method)
11-21 11:19:16.991: I/dalvikvm(30261): at java.lang.String.getBytes(String.java:861)
11-21 11:19:16.991: I/dalvikvm(30261): at java.lang.String.getBytes(String.java:845)
11-21 11:19:16.991: I/dalvikvm(30261): at org.apache.http.entity.StringEntity.<init>(StringEntity.java:64)
11-21 11:19:16.991: I/dalvikvm(30261): at ti.modules.titanium.network.TiHTTPClient.handleURLEncodedData(TiHTTPClient.java:1247)
11-21 11:19:16.991: I/dalvikvm(30261): at ti.modules.titanium.network.TiHTTPClient.access$2000(TiHTTPClient.java:99)
11-21 11:19:16.991: I/dalvikvm(30261): at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1164)
11-21 11:19:16.991: I/dalvikvm(30261): at java.lang.Thread.run(Thread.java:856)
11-21 11:19:16.991: E/TiHttpClient(30261): (TiHttpClient-2) [24623,676845] HTTP Error (java.lang.OutOfMemoryError): java.lang.OutOfMemoryError
11-21 11:19:16.991: E/TiHttpClient(30261): java.lang.OutOfMemoryError
11-21 11:19:16.991: E/TiHttpClient(30261): at java.nio.charset.Charsets.toUtf8Bytes(Native Method)
11-21 11:19:16.991: E/TiHttpClient(30261): at java.lang.String.getBytes(String.java:861)
11-21 11:19:16.991: E/TiHttpClient(30261): at java.lang.String.getBytes(String.java:845)
11-21 11:19:16.991: E/TiHttpClient(30261): at org.apache.http.entity.StringEntity.<init>(StringEntity.java:64)
11-21 11:19:16.991: E/TiHttpClient(30261): at ti.modules.titanium.network.TiHTTPClient.handleURLEncodedData(TiHTTPClient.java:1247)
11-21 11:19:16.991: E/TiHttpClient(30261): at ti.modules.titanium.network.TiHTTPClient.access$2000(TiHTTPClient.java:99)
11-21 11:19:16.991: E/TiHttpClient(30261): at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1164)
11-21 11:19:16.991: E/TiHttpClient(30261): at java.lang.Thread.run(Thread.java:856)
11-21 11:19:16.991: I/TiHttpClient(30261): (TiHttpClient-2) [1,676846] Sending error java.lang.OutOfMemoryError
I'm not able to find a maximum size hardcoded. My feeling is that it would either be limited by device memory or a server setting.
This may be a duplicate of TIMOB-15594.
Closing ticket as duplicate with reference to the linked issues above.