Convert image Binary Data to Base64 in mobile client side or Javascript

Hi,

I want to convert the image Binary Data to base64 without using server action "BinaryToBase64". Is there any client action or javascript code to convert binary data getting from upload control  to base64 that works offline .


Thanks,

Dileep.

Hi Dileep,

I am not sure if any client action available in outsystems for this but you can use javascript to convert binarydata to base64 string. You can use below method

window.btoa(yourbinarydata);

or just 

btoa(yourbinarydata);

Assign its output to output variable of your js block and use in the client action for further processing.

Hi Dileep,

I've provided a sample oml, check if that is what you need.

Solution

Or you can use this component as it already has this implementation

https://www.outsystems.com/forge/component-overview/3242/binarydata-client-side

Solution

Nikhil Gaur wrote:

Hi Dileep,

I am not sure if any client action available in outsystems for this but you can use javascript to convert binarydata to base64 string. You can use below method

window.btoa(yourbinarydata);

or just 

btoa(yourbinarydata);

Assign its output to output variable of your js block and use in the client action for further processing.

Thanks Nikhil but I already tried this but what I observed its not returning the same base64 output as we are getting using server action BinaryToBase64.So when I am passing it not getting expected results what i was getting when converted using server action.


Thanks,

Dileep Verma


Pedro Neto wrote:

Hi Dileep,

I've provided a sample oml, check if that is what you need.

Pedro, using 

btoa(decodeURI(encodeURIComponent($parameters.BinaryImageData)))

I am not getting the same output , what was getting using BinaryToBase64 for same image, getting encoded base64 text,  results the behaviour is not same.


Thanks,

Dileep Verma


Nikhil Gaur wrote:

Or you can use this component as it already has this implementation

https://www.outsystems.com/forge/component-overview/3242/binarydata-client-side

Thanks Nikhil, simple trick, just assigned binaryData value  to text type output variable solved the problem.

Hi Dileep,

Yes, even I was shocked when I saw this code in the component. I was not expacting it to be that simple :)