Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Ti.Utils.base64encode returns object. How do I get a string?

The API Docs state that Ti.Utils.base64encode returns a string. However, I'm getting an object of type 'TiBlob'.

Is there a way I can get the actual string that I can store in Ti.App.Properties and use for Basic HTTP Authentication?

Thanks in advance.

— asked November 30th 2010 by Warren Harrison
  • authentication
  • base64encode
  • http
  • string
1 Comment
  • FYI: I've tried Ti.Utils.base64encode(myVar).toString() with no luck.

    — commented November 30th 2010 by Warren Harrison

2 Answers

  • I stand corrected. The following did fix my problem.

    var loginHash = Ti.Utils.base64encode( txtUser.value + ':' + txtPass.value );
    Ti.App.Properties.setString( "loginHash", loginHash.toString() );
    

    Perhaps the API docs should be updated to reflect that Ti.Utils.base64encode returns an object though.

    — answered November 30th 2010 by Warren Harrison
    permalink
    0 Comments
  • Are you sure that "myVar" is a string?

    I have this line

    var key = Ti.Utils.base64encode(JSON.stringify(data));

    where "data" is a JSON object, and that gives me an encoding string value with absolutely no issues

    — answered November 30th 2010 by Stephen Gilboy
    permalink
    1 Comment
    • I should have been more thorough in my original post, but I am concatenating values from two text fields (see be code sample above). It appears to be the act of storing the encoded data in the Properties object that screws things up. If I .toString() it first, it seems to be retrievable as expected.

      Thanks for your help.

      — commented November 30th 2010 by Warren Harrison
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.