[TIMOB-1604] Android: base64 encoding/decoding of Blob cannot be round-tripped successfully
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Trivial |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-05-14T14:49:57.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.5.0 |
Components | Android |
Labels | n/a |
Reporter | Bill Dawson |
Assignee | Neeraj Gupta |
Created | 2011-04-15T02:57:11.000+0000 |
Updated | 2012-05-14T14:49:58.000+0000 |
Description
You cannot use Titanium.Utils.base64encode & Titanium.Utils.base64decode successfully to round-trip the encoding / decoding of a blob. In other words, you don't get back the same set of bytes that you originally started with.
Failcase app.js (make sure you have KS_nav_ui.png in your Resources folder; it's there by default with new projects):
var win = Ti.UI.createWindow({fullscreen: true, exitOnClose:true});
var file = Ti.Filesystem.getFile('KS_nav_ui.png');
var blob1 = file.read();
var base64 = Ti.Utils.base64encode(blob1);
var blob2 = Ti.Utils.base64decode(base64);
var thumbnail1 = Titanium.UI.createView({left: 0, top: 0, width: 46, height: 43});
thumbnail1.backgroundImage = 'KS_nav_ui.png'; // the orig, which obviously works
var thumbnail2 = Titanium.UI.createView({left: 56, top: 0, width: 46, height: 43});
var thumbnail3 = Titanium.UI.createView({left: 112, top: 0, width: 46, height: 43});
win.add(thumbnail1); win.add(thumbnail2); win.add(thumbnail3);
var tempDir = Titanium.Filesystem.createTempDirectory();
tempDir.createDirectory();
// Blob from original file
var file1 = Titanium.Filesystem.getFile(tempDir.nativePath, 'file1.png');
file1.write(blob1);
thumbnail2.backgroundImage = file1.nativePath;
// Base64 encoded-then-decoded blob
var file2 = Titanium.Filesystem.getFile(tempDir.nativePath, 'file2.png');
file2.write(blob2);
thumbnail3.backgroundImage = file2.nativePath;
win.open();
You should see three identical images when that runs. Instead, you'll see only two.
(from [fd880341bc564607ed68650fd73660f57131d23f]) [#1604 state:fixed-in-qa] When base64encoding a blob, don't force it to its string representation if you don't have to. That makes it unusable for binary files, images, etc. http://github.com/appcelerator/titanium_mobile/commit/fd880341bc564607ed68650fd73660f57131d23f"> http://github.com/appcelerator/titanium_mobile/commit/fd880341bc564...
fixed on android using 1.4.1.ca7b78 device an simulator. Opening a new issue for iOS to have functional parity.
#1611 for iOS
Reopen via customer request.
Associated Helpdesk Ticket
http://appc.me/c/APP-486271Looks like the docs need to be updated. base64encode() returns a TiBlob, and you will need to call getText() on TiBlob to get the string value
Tested with 2.0.1GA2 on a Samsung Galaxy S2 (2.3.6). Unable to reproduce the issue. Ticket closed.