Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27532] iOS: Ti.Utils.base64encode(image).toString() Broken on iOS 9 and 10

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionDuplicate
Resolution Date2019-12-03T18:40:02.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
LabelsACF
ReporterFazlul Haque
AssigneeVijay Singh
Created2019-11-07T16:28:33.000+0000
Updated2019-12-06T17:49:49.000+0000

Description

Hello, Ti.Utils.base64encode(image).toString() is broken on iOS 9 and 10. This function returns [object TiBlob] when it should return the base64 encoded string. On iOS 11, 12, and 13 it works as expected. *Test Environment:* SDK version: 8.2.1.GA Appcelerator Command-Line Interface, version 7.1.1 iOS Device: iPhone 6 plus(12.4.1), iPod 5G (9.3.5) *Test Code:* index.xml
<Alloy>
	<Window class="container">
		<Label class="label" onClick="getImage">Get Image from Photos</Label>
		<Label id="base64Text" class="label" />
	</Window>
</Alloy>
index.js
var image = null;

function getImage() {
	Ti.Media.openPhotoGallery({
		success: function(event){
			image = event.media;

			var imageText = Ti.Utils.base64encode(image).toString();

			// Rendering thousands of characters is error prone so 
			// I trim the string for this proof of concept.
			if (imageText.length > 100) {
				imageText = imageText.substring(0, 100);
			}

		  	$.base64Text.text = imageText;
		},
		allowEditing: false,
		mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO]
	});
}
$.index.open();
You can check the attached project also. *Steps to reproduce the issue:* 1. Run the above code on iOS 9 or 10 2. Click on the "Get Image from Photos" label and it will choose an image from gallery. 3. You will get *"[object TiBlob]"* but it should be returned the base64 encoded string. Thanks

Attachments

FileDateSize
blob-to-string.zip2019-11-07T16:26:22.000+00008665196

Comments

  1. Vijay Singh 2019-11-12

    From SDK 8.1.0.GA, toString() API is broken for TiBlob. Please ask to use property [text](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Blob-property-text) until we properly fix it. e.g var imageText = Ti.Utils.base64encode(image).text; Updated index.js -
       function getImage() {
       	Ti.Media.openPhotoGallery({
       		success: function(event){
       			image = event.media;
        
                               var imageText = Ti.Utils.base64encode(image).text;
        
       			// Rendering thousands of characters is error prone so 
       			// I trim the string for this proof of concept.
       			if (imageText.length > 100) {
       				imageText = imageText.substring(0, 100);
       			}
        
       		  	$.base64Text.text = imageText;
       		},
       		allowEditing: false,
       		mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO]
       	});
       }
       $.index.open();
       
  2. Vijay Singh 2019-12-03

    Duplicate of TIMOB-27350.
  3. Adam Paxton 2019-12-05

    Is TIMOB-27350 internal only ticket? I am unable to view/follow it.

JSON Source