[TIMOB-15594] Android: base64 encode of a large file fails
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-05-23T22:01:17.000+0000 |
Affected Version/s | Release 3.2.0, Release 3.2.1 |
Fix Version/s | 2014 Sprint 08, 2014 Sprint 08 SDK, Release 3.3.0, Release 3.4.0 |
Components | Android |
Labels | supportTeam |
Reporter | Davide Cassenti |
Assignee | Sunila |
Created | 2013-10-28T11:12:13.000+0000 |
Updated | 2014-07-31T21:04:17.000+0000 |
Description
Problem description
Trying to use base64encode with a very large file, fails with an 'out of memory' error.Use case
The use case would be to upload a base64-encoded file using an HTTPClient. The conversion to base64 fails.Sample code
var filename = "SOME_LARGE_FILE";
var file = Titanium.Filesystem.getFile(filename);
var toUpload = file.read();
var ws = {
file_name: filename,
data: Ti.Utils.base64encode(toUpload)
};
var xhr = Ti.Network.createHTTPClient({
onload: function(e) {
Ti.API.info(this.responseText);
}
});
xhr.open('POST', 'SOME_UPLOAD_URL');
xhr.send(ws);
Attachments
File | Date | Size |
---|---|---|
movie.mp4 | 2014-05-13T18:02:05.000+0000 | 2549211 |
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. https://github.com/appcelerator/titanium_mobile/pull/5261
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. https://github.com/appcelerator/titanium_mobile/pull/5261
Run the following code to reproduce the issue. After merging the fix, set the the 'tryTheFix' to true and run the sample again to see the fix
Reopening the ticket.
1. When tryTheFix = false:
We get the following errors:2. When tryTheFix = true:
We see these logs:Lokesh, The error you get with 1 may be because the server is terminating the connection because it is taking too long. Can you attach or upload the file you tried in some place? I am looking in to 2.
Hi [~sunila], The link for the attachment is : https://www.dropbox.com/s/2wt6yo16i1lto2n/wildlife.wmv
New PR submitted https://github.com/appcelerator/titanium_mobile/pull/5677
To avoid getting Broken pipe error, you could setup a local server to accept the file upload. Here is the PHP script to try
up in Apache with PHP 1. Save the file as upload.php in htdocs directory 2.Create a subdirectory called temp under htdocs 3. 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 4. You should see the proper response once the file is uploaded. Try something around 10MB otherwise it may take a long time. 5. Uploaded file will be under htdocs/temp, open and verify if it is base64 encoded.
3.3.X PR: https://github.com/appcelerator/titanium_mobile/pull/5733
Verified fixed on: Mac OSX 10.9.3 Appcelerator Studio, build: 3.3.0.201405271647 Titanium SDK, build: 3.3.0.v20140528144113 Titanium CLI, build: 3.3.0-beta Alloy: 1.4.0-beta Android Device: Nexus 4 (4.4) Large file successfully uploaded with base64 encoding. Closing.
update doc: https://github.com/appcelerator/titanium_mobile/pull/5942