{ "id": "121690", "key": "TIMOB-15594", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "16092", "description": "2014 Sprint 08", "name": "2014 Sprint 08", "archived": true, "released": true, "releaseDate": "2014-04-24" }, { "id": "16093", "description": "2014 Sprint 08 SDK", "name": "2014 Sprint 08 SDK", "archived": true, "released": true, "releaseDate": "2014-04-24" }, { "id": "15422", "description": "Release 3.3.0", "name": "Release 3.3.0", "archived": false, "released": true, "releaseDate": "2014-07-16" }, { "id": "15972", "description": "Release 3.4.0", "name": "Release 3.4.0", "archived": false, "released": true, "releaseDate": "2014-09-28" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2014-05-23T22:01:17.000+0000", "created": "2013-10-28T11:12:13.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "supportTeam" ], "versions": [ { "id": "14982", "description": "Release 3.2.0", "name": "Release 3.2.0", "archived": false, "released": true, "releaseDate": "2013-12-19" }, { "id": "15856", "description": "Release 3.2.1", "name": "Release 3.2.1", "archived": false, "released": true, "releaseDate": "2014-02-10" } ], "issuelinks": [ { "id": "39477", "type": { "id": "10002", "name": "Duplicate", "inward": "is duplicated by", "outward": "duplicates" }, "inwardIssue": { "id": "122797", "key": "TIMOB-15792", "fields": { "summary": "Android: uploading a large base64 encoded file with HTTPClient crashes due to memory error", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "priority": { "name": "High", "id": "2" }, "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false } } } } ], "assignee": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "updated": "2014-07-31T21:04:17.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "h2. Problem description\r\nTrying to use base64encode with a very large file, fails with an 'out of memory' error.\r\n\r\nh2. Use case\r\nThe use case would be to upload a base64-encoded file using an HTTPClient. The conversion to base64 fails.\r\n\r\nh2. Sample code\r\n{code}\r\nvar filename = \"SOME_LARGE_FILE\";\r\nvar file = Titanium.Filesystem.getFile(filename);\r\n\r\nvar toUpload = file.read();\r\nvar ws = {\r\n file_name: filename,\r\n data: Ti.Utils.base64encode(toUpload)\r\n};\r\n\r\nvar xhr = Ti.Network.createHTTPClient({\r\n onload: function(e) {\r\n Ti.API.info(this.responseText);\r\n }\r\n});\r\nxhr.open('POST', 'SOME_UPLOAD_URL');\r\nxhr.send(ws);\r\n{code}", "attachment": [ { "id": "48022", "filename": "movie.mp4", "author": { "name": "hpham", "key": "hpham", "displayName": "Hieu Pham", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-05-13T18:02:05.000+0000", "size": 2549211, "mimeType": "video/mp4" } ], "flagged": false, "summary": "Android: base64 encode of a large file fails", "creator": { "name": "dcassenti", "key": "dcassenti", "displayName": "Davide Cassenti", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "dcassenti", "key": "dcassenti", "displayName": "Davide Cassenti", "active": true, "timeZone": "Europe/Berlin" }, "environment": "Android 4.3\r\nSDK 3.1.2\r\nSDK 3.1.3", "closedSprints": [ { "id": 104, "state": "closed", "name": "2014 Sprint 10 SDK", "startDate": "2014-05-12T16:00:00.000Z", "endDate": "2014-05-24T00:00:00.000Z", "completeDate": "2014-05-27T18:11:47.424Z", "originBoardId": 114 } ], "comment": { "comments": [ { "id": "289793", "author": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "body": "Modified the code to use the stream directly in the HTTPClient to avoid memory allocation. TiBlob is modified to support stream and take file as input.\r\n\r\nhttps://github.com/appcelerator/titanium_mobile/pull/5261", "updateAuthor": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "created": "2014-01-27T14:13:15.000+0000", "updated": "2014-01-27T14:13:15.000+0000" }, { "id": "289794", "author": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "body": "Modified the code to use the stream directly in the HTTPClient to avoid memory allocation. TiBlob is modified to support stream and take file as input.\r\n\r\nhttps://github.com/appcelerator/titanium_mobile/pull/5261", "updateAuthor": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "created": "2014-01-27T14:14:19.000+0000", "updated": "2014-01-27T14:14:19.000+0000" }, { "id": "289795", "author": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "body": "Run the following code to reproduce the issue. \r\nAfter merging the fix, set the the 'tryTheFix' to true and run the sample again to see the fix\r\n\r\n{code}\r\n\tvar win = Ti.UI.createWindow();\r\n\twin.open();\r\n\t \r\n\t \r\n\tvar percent_done = 0;\r\n\t \r\n\tvar xhr = Ti.Network.createHTTPClient({\r\n\t onload : function(e) {\r\n\t \t Ti.API.info(\"onLoad:\"+this.responseText);\r\n\t \r\n\t },\r\n\t onerror : function(e) {\r\n\t \t Ti.API.info(\"e.error: \"+e.error);\r\n\t },\r\n\t onreadystatechange: function(e){\r\n\t \t Ti.API.info(\"onreadystatechange: \"+this.readyState); \r\n\t },\r\n\t timeout: 10000\r\n\t});\r\n\t \r\n\t \r\n\tfunction upload(){\r\n\t console.log(\"STARTING UPLOAD\");\r\n\t var filename = \"Wildlife.wmv\";\r\n\t var url = \"http://www.w3schools.com/ajax/demo_post.asp\"; //using this server for simplicity's sake\r\n\t var file = Ti.Filesystem.getFile(Ti.Filesystem.getResourcesDirectory()+filename); //just use any large-ish file, 500kb+ or so\r\n\t xhr.open(\"POST\", url);\r\n\t // set 'tryTheFix' to true to see the fix\r\n\t var tryTheFix = false;\r\n\t var ws;\r\n\t if (tryTheFix) {\r\n\t ws = {\r\n\t file_name: filename,\r\n\t data: Ti.Utils.base64encode(file)\r\n\t };\r\n\t } else {\r\n\t var toUpload = file.read();\r\n\t ws = {\r\n\t file_name: filename,\r\n\t data: Ti.Utils.base64encode(toUpload)\r\n\t };\r\n\t }\r\n\t xhr.send(ws); \r\n\t} \r\n\t \r\n\tupload();\r\n{code}", "updateAuthor": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "created": "2014-01-27T14:18:51.000+0000", "updated": "2014-03-26T14:42:41.000+0000" }, { "id": "304050", "author": { "name": "lchoudhary", "key": "lchoudhary", "displayName": "Lokesh Choudhary", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Reopening the ticket.\r\n\r\nh5.1. When tryTheFix = false:\r\nWe get the following errors:\r\n{code}\r\n[ERROR] : TiHttpClient: (TiHttpClient-1) [3259,3259] HTTP Error (java.net.SocketException): sendto failed: EPIPE (Broken pipe)\r\n[ERROR] : TiHttpClient: java.net.SocketException: sendto failed: EPIPE (Broken pipe)\r\n[ERROR] : TiHttpClient: \tat libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:499)\r\n[ERROR] : TiHttpClient: \tat libcore.io.IoBridge.sendto(IoBridge.java:468)\r\n[ERROR] : TiHttpClient: \tat java.net.PlainSocketImpl.write(PlainSocketImpl.java:507)\r\n[ERROR] : TiHttpClient: \tat java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)\r\n[ERROR] : TiHttpClient: \tat java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269)\r\n[ERROR] : TiHttpClient: \tat org.apache.http.impl.io.AbstractSessionOutputBuffer.flushBuffer(AbstractSessionOutputBuffer.java:87)\r\n[ERROR] : TiHttpClient: \tat org.apache.http.impl.io.AbstractSessionOutputBuffer.flush(AbstractSessionOutputBuffer.java:94)\r\n[ERROR] : TiHttpClient: \tat org.apache.http.impl.AbstractHttpClientConnection.doFlush(AbstractHttpClientConnection.java:169)\r\n[ERROR] : TiHttpClient: \tat org.apache.http.impl.SocketHttpClientConnection.close(SocketHttpClientConnection.java:192)\r\n[ERROR] : TiHttpClient: \tat org.apache.http.impl.conn.DefaultClientConnection.close(DefaultClientConnection.java:161)\r\n[ERROR] : TiHttpClient: \tat org.apache.http.impl.conn.AbstractPooledConnAdapter.close(AbstractPooledConnAdapter.java:158)\r\n[ERROR] : TiHttpClient: \tat org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)\r\n[ERROR] : TiHttpClient: \tat org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)\r\n[ERROR] : TiHttpClient: \tat org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)\r\n[ERROR] : TiHttpClient: \tat org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:653)\r\n[ERROR] : TiHttpClient: \tat org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:637)\r\n[ERROR] : TiHttpClient: \tat ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1291)\r\n[ERROR] : TiHttpClient: \tat java.lang.Thread.run(Thread.java:841)\r\n[ERROR] : TiHttpClient: Caused by: libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe)\r\n[ERROR] : TiHttpClient: \tat libcore.io.Posix.sendtoBytes(Native Method)\r\n[ERROR] : TiHttpClient: \tat libcore.io.Posix.sendto(Posix.java:156)\r\n[ERROR] : TiHttpClient: \tat libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)\r\n[ERROR] : TiHttpClient: \tat libcore.io.IoBridge.sendto(IoBridge.java:466)\r\n[ERROR] : TiHttpClient: \t... 16 more\r\n{code}\r\n\r\nh5.2. When tryTheFix = true:\r\nWe see these logs:\r\n{code}\r\n[ERROR] : TiHttpClient: (KrollRuntimeThread) [72,72] Error adding post data (data): bad base-64\r\n[INFO] : onreadystatechange: 1\r\n[DEBUG] : OpenGLRenderer: Enabling debug mode 0\r\n[TRACE] : RenderScript: Application requested CPU execution\r\n[TRACE] : RenderScript: 0x79e180b0 Launching thread(s), CPUs 4\r\n[DEBUG] : Window: Checkpoint: postWindowCreated()\r\n[INFO] : onreadystatechange: 3\r\n[INFO] : onreadystatechange: 3\r\n[DEBUG] : skia: --- SkImageDecoder::Factory returned null\r\n[DEBUG] : skia: --- SkImageDecoder::Factory returned null\r\n[INFO] : onreadystatechange: 4\r\n[INFO] : onLoad:

This content was requested using the POST method.

\r\n[INFO] :

Requested at: 5/8/2014 1:46:25 PM

\r\n[DEBUG] : HTTPClient: The persistent handle is disposed.\r\n{code}", "updateAuthor": { "name": "lchoudhary", "key": "lchoudhary", "displayName": "Lokesh Choudhary", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-05-08T17:52:48.000+0000", "updated": "2014-05-08T17:53:47.000+0000" }, { "id": "304349", "author": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "body": "Lokesh,\r\nThe error you get with 1 may be because the server is terminating the connection because it is taking too long.\r\nCan you attach or upload the file you tried in some place?\r\nI am looking in to 2.", "updateAuthor": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "created": "2014-05-12T14:12:04.000+0000", "updated": "2014-05-12T14:12:04.000+0000" }, { "id": "304381", "author": { "name": "lchoudhary", "key": "lchoudhary", "displayName": "Lokesh Choudhary", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Hi [~sunila],\r\nThe link for the attachment is : https://www.dropbox.com/s/2wt6yo16i1lto2n/wildlife.wmv", "updateAuthor": { "name": "lchoudhary", "key": "lchoudhary", "displayName": "Lokesh Choudhary", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-05-12T16:46:55.000+0000", "updated": "2014-05-12T16:47:38.000+0000" }, { "id": "304583", "author": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "body": "New PR submitted\r\n\r\nhttps://github.com/appcelerator/titanium_mobile/pull/5677", "updateAuthor": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "created": "2014-05-13T16:32:14.000+0000", "updated": "2014-05-13T16:32:14.000+0000" }, { "id": "305299", "author": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "body": "To avoid getting Broken pipe error, you could setup a local server to accept the file upload.\r\nHere is the PHP script to try\r\n\r\n{code}\r\n\"; \r\necho \"Destination=\" . $destination_path . \"
\"; \r\necho \"Target path=\" . $target_path . \"
\"; \r\necho \"Size=\" . $_FILES['data']['size'] . \"
\"; \r\n\r\n\r\nif(move_uploaded_file($_FILES['data']['tmp_name'], $target_path)) {\r\n echo \"The file \". basename( $_FILES['data']['name']). \r\n \" has been uploaded\";\r\n} else{\r\n echo \"There was an error uploading the file, please try again!\";\r\n}\r\n?>\r\n{code}\r\n\r\n up in Apache with PHP\r\n1. Save the file as upload.php in htdocs directory\r\n2.Create a subdirectory called temp under htdocs\r\n3. Change the url in the code to point to upload.php (you may need to use machine ip address instead of the localhost if you are debugging from eclipse) something like http://192.168.1.142:8080/upload.php\r\n4. You should see the proper response once the file is uploaded. Try something around 10MB otherwise it may take a long time.\r\n5. Uploaded file will be under htdocs/temp, open and verify if it is base64 encoded. \r\n", "updateAuthor": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-05-16T17:06:51.000+0000", "updated": "2014-05-23T17:06:51.000+0000" }, { "id": "306361", "author": { "name": "hpham", "key": "hpham", "displayName": "Hieu Pham", "active": true, "timeZone": "America/Los_Angeles" }, "body": "3.3.X PR: https://github.com/appcelerator/titanium_mobile/pull/5733", "updateAuthor": { "name": "hpham", "key": "hpham", "displayName": "Hieu Pham", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-05-23T23:29:13.000+0000", "updated": "2014-05-23T23:29:13.000+0000" }, { "id": "306860", "author": { "name": "sdowse", "key": "sdowse", "displayName": "Samuel Dowse", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Verified fixed on:\r\nMac OSX 10.9.3\r\nAppcelerator Studio, build: 3.3.0.201405271647\r\nTitanium SDK, build: 3.3.0.v20140528144113\r\nTitanium CLI, build: 3.3.0-beta\r\nAlloy: 1.4.0-beta\r\nAndroid Device: Nexus 4 (4.4)\r\n\r\nLarge file successfully uploaded with base64 encoding.\r\nClosing.", "updateAuthor": { "name": "sdowse", "key": "sdowse", "displayName": "Samuel Dowse", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-05-29T17:51:43.000+0000", "updated": "2014-05-29T17:51:43.000+0000" }, { "id": "316516", "author": { "name": "pwang", "key": "pwang", "displayName": "Ping Wang", "active": true, "timeZone": "America/Los_Angeles" }, "body": "update doc: https://github.com/appcelerator/titanium_mobile/pull/5942", "updateAuthor": { "name": "pwang", "key": "pwang", "displayName": "Ping Wang", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-07-31T21:03:16.000+0000", "updated": "2014-07-31T21:03:16.000+0000" } ], "maxResults": 22, "total": 22, "startAt": 0 } } }