[TIMOB-27532] iOS: Ti.Utils.base64encode(image).toString() Broken on iOS 9 and 10
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | None |
| Status | Closed |
| Resolution | Duplicate |
| Resolution Date | 2019-12-03T18:40:02.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | iOS |
| Labels | ACF |
| Reporter | Fazlul Haque |
| Assignee | Vijay Singh |
| Created | 2019-11-07T16:28:33.000+0000 |
| Updated | 2019-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
| File | Date | Size |
|---|---|---|
| blob-to-string.zip | 2019-11-07T16:26:22.000+0000 | 8665196 |
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();Duplicate of TIMOB-27350.
Is TIMOB-27350 internal only ticket? I am unable to view/follow it.