Thunkable X Base 64 Encoding!

I have been working on an app to communicate with the Particle API, but the API requires some of the text information to be Base 64 Encoded for it to interpret it. How is this possible with Thunkable X?

I have a functional version of my app running with Thunkable Classic, as there is an extension that directly encodes any string to base64, but I badly need the app to have cross platform support.

Any help would be greatly appreciated! Thanks,
Isaac

1 Like

In the moment , its not posible

i have a solution but its… well

u can make a web html , get the text converts to base64 and then take it again to the app , whit json ,or airtable

1 Like

Do you have an example of how this would be done with Thunkable X? I am alright with anything at this point, haha.

1 Like

Hi,

Encode to Base64

http://api.foxtools.ru/v2/Base64?mode=1&text=

5 Likes

Perfect. :+1: :white_check_mark:

Do I have to use API bloks to use this code or could I use this bloks without linking any API?
I’d prefer not using and manage external API but decode and encode inside the app.

Thanks

If your base64 value is static, you could hard code it in the app. The API I’m using is - it wants a client ID and secret encoded, so I just did it once with an online encoder and pasted the value into an app variable.

If that value is dynamic, then you need some way to get it. I have a little piece of JavaScript that takes the string to encode and passes it back encoded. It only takes the web viewer block to use it, as long as you have a webpage to put the JavaScript on. Let me know if you want to see the blocks and JS code.

Here’s the JS:

<script>
//Use this if you want to pass in 'code' as part of the URL string (yourdomain.com?code=CODESTRINGHERE)
  const queryString = window.location.search;
  const urlParams = new URLSearchParams(queryString);
  const my_code = urlParams.get('code')
 
// currently I just pass back the code that was passed in, but mash it up with the second bit of code below, and you've got a base64 encoder/
 
ThunkableWebviewerExtension.postMessage(my_code);
 
//alternately, use the code below to take a message in, encode it, and pass it back.
 
// when we get a message from the app, display it on the page
//ThunkableWebviewerExtension.receiveMessage(function(message) {
  // Do something with your message
//  const reply_message = 'base64,' + btoa(message);
//ThunkableWebviewerExtension.postMessage(reply_message);
//}); 
</script>

Or if you insist on an “all-Thunkable” solution, you could implement this algorithm. I don’t see anything there that /couldn’t/ be done with blocks. Base64 Encode Algorithm | Base64 Algorithm | Learn | Base64

2 Likes

Many thanks. Your answer was very helpful and detailed

1 Like