Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15792] Android: uploading a large base64 encoded file with HTTPClient crashes due to memory error

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionDuplicate
Resolution Date2014-07-31T21:03:57.000+0000
Affected Version/sRelease 2.1.4, Release 3.1.2
Fix Version/sRelease 3.4.0
ComponentsAndroid
Labelsn/a
ReporterDavide Cassenti
AssigneePing Wang
Created2013-11-22T10:58:00.000+0000
Updated2017-03-23T05:24:32.000+0000

Description

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

Attachments

FileDateSize
testfile_5MB2013-11-26T11:42:05.000+00005242880

Comments

  1. Ingo Muschenetz 2014-01-08

    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.
  2. Sunila 2014-02-12

    This may be a duplicate of TIMOB-15594.
  3. Lee Morris 2017-03-23

    Closing ticket as duplicate with reference to the linked issues above.

JSON Source