Javascript url to base64 encoder

Hi, im trying to create a javascript component, to encode an image url to base64, but i have no knowledge in js, could you help?

I know there is already a base64 encoder function, but the urls im using are from instagram and are getting blocked , bu creating my own js component, im hopping it wont get blocked,

Lastly, there are many example scripts but i dont know how to implement them.

hey @Andreas_Becker could you help? im asking, because you helped me with js in the past.

return { result: encodeBase64(inputs.url) };

function encodeBase64(data) {
    console.log('data', data)
    if (typeof btoa === "function") {
        return btoa(data);
    } else if (typeof Buffer === "function") {
        return Buffer.from(data, "utf-8").toString("base64");
    } else {
        throw new Error("Failed to determine the platform specific encoder");

This js converts “Login • Instagram” to “aHR0cHM6Ly93d3cuaW5zdGFncmFtLmNvbS9wL0NZX19qanNLQlQ4Lw==”


woo thanks for the rapid help, im so sorry, even though your code works perfectly, i failed to mention, that the urls are images like this one,

at the moment, the code outputs the url in base64, do you think you can make it encoding the image of the url?
Again so sorry i didnt know it would make such a difference…

from my small research, i think that to encode the image is no different that encoding the content of the url, and adding this in the beginning.

Ok, so you want the image, that is shown when the link in the browser is opened, to be encoded as base64? So you can store it and later show as data image?

This can be done f.e. with this code: javascript - CONVERT Image url to Base64 - Stack Overflow but you can possibly get into trouble with CORS problems. Just try.

1 Like

I’m on mobile right now, but I seem to remember there being a Base64 converter in AG. It might be a flow function, but I also remember it being an option inside the logic functions, too.

You should be able to pair the AG version with URLs, if you get a bit creative with flow functions or want to dig into the logic by hand.

For what it’s worth, I’ve noticed that AG tends to run flow functions and logic functions more efficiently than raw JavaScript.

perfect, thank you very much i will implement it!!

yeah, there is a flow function to convert the image url,but the instagram blocks them when opened through appgyver, so i thought to try with Js maybe it works.

Hi, i just tried with what you suggested, but i sure im doing something wrong.

Line 14 needs a semicolon.

Run it as:
try { // Do the Base64 thing } catch (error) { console.log(error); }

See what error that kicks out.

1 Like

Hey, thanks for the help, but i tried the code in an online compiler, and even though it works, it doesnt work with my urls (from instagram), so the only thing left is a base64 encoder api (which i cant find but maybe i will make one)