Base 64 Encoding

I needed a base64 encoder for a web api. But in Thunkable X I did not find any component to suit my needs. Also sending username and passwords to an external API was too insecure for me. I found two solutions to this problem.

First Solution:

This implies having access to a hosting service where you could host a PHP script that would do the conversion for you and WebAPI componnent.
PHP Script:

<?php
$str = $_GET['string'];
$myObj->response = base64_encode($str);
$myJSON = json_encode($myObj);
echo $myJSON;
?>

Thunkable:

Second Solution:
The second solution is more elegant since you have a function inside your app that is doing the conversion.

From my testing looks like this is working ok. If you find some errors let me know. Probably are due do to the asci conversion list.

Here is a sample project:
https://x.thunkable.com/copy/908ad8848e38958367e82fbb8ce2991a

Thank you!

2 Likes

Hi,

Thank you for your solution, but unfortunately the second example does not work, and there is a better solution on the scrWebApi.

https://x.thunkable.com/projects/5d70f93f8a62b4079eedaff2/project/properties/designer/

@actech if you like to send your data to unknown sources then yes you are right. Btw your link does the same as my first solution.

Related to the fact that the example is not working, can you please detail a little bit. What string you try that did not work?

I used the line with the Cyrillic alphabet.

Another problem is that it is not possible to copy blocks between projects in Thunkable X. How many users do you think will want to manually create large function blocks for their project? I think very few.

Aaa ok. To work also with other characters beside the standard ASCI you need to update the list for ASCI code and after will work.

Copy/paste function is a Thunkable issue.:smile: For example I did copy the blocks one by one to another project because first time I was using http://api.foxtools.ru, but i need to encode username and password, so sending them to an obscure site that is not even https did not look very safe to me(noob here not expert in security).

In the end is another way to look at the problem till a proper crypto block will be implemented in thunkable.

To encode a password, they use not a base64, but a cryptographic function. There are universal decoders with which it will not be difficult to get a password from your base64 string.

Hello Guys,

http://api.foxtools.ru/v2/Base64 webAPI stopped working for me. It returns “Network request failed”

This site can’t be reached http://api.foxtools.ru/v2/Base64 is unreachable.

ERR_ADDRESS_UNREACHABLE

Is it working for you? Any ideas why?

Thanks,
Marco

as an alternative, you can use the code i used in this simple base64 encoder/decoder - if you’re converting short strings (not files!). click on the link below.

1 Like

New version on scrWebApi

https://x.thunkable.com/projects/5d70f93f8a62b4079eedaff2/project/properties/designer/

Thanks for the suggestion. Unfortunately I need a Base64 encoder for images. I’m converting small thumbnail images to Base64 so I can save it locally in a local storage so the app can still be used offline. Any other suggestion?

Thanks for the sample Base64 encoder.

Also, will this work for an image that’s stored in Cloudinary? I used to use the [http://api.foxtools.ru] and I supply the URL of the image. The sample you showed looks like it accepts a text then it converts to Base64. What I need it a BAse64 encoder that accepts URL of the image then it returns the Base64 string.

Thanks,
Marco

There are two ways to solve your problem:

  1. Find a service that can perform this task

  2. Try using JavaScript to do this:

    function toDataURL(url, callback) {
    var xhr = new XMLHttpRequest();
    xhr.onload = function() {
    var reader = new FileReader();
    reader.onloadend = function() {
    callback(reader.result);
    }
    reader.readAsDataURL(xhr.response);
    };
    xhr.open(‘GET’, url);
    xhr.responseType = ‘blob’;
    xhr.send();
    }

    toDataURL(‘https://www.gravatar.com/avatar/d50c83cc0c6523b4d3f6085295c953e0’, function(dataUrl) {
    console.log(‘RESULT:’, dataUrl)
    })

Thanks! I’ll try the javascript solution but I think the best solution for me is to find another API that encodes imageURL to Base64 like what [http://api.foxtools.ru] does. I’ve been searching for days and I cannot find any. I’ve searched in RapidAPI, Google APIs, Amazon, or Microsoft but no luck. It’s weird that no one else provides a simple API that encodes an image to Base64. I just saw some online tools but they don’t have API endpoints.

Let me know if you guys know of any.

Thanks,
Marco

http://api.foxtools.ru] is up again and working perfect! I just wanted to give an update.

1 Like