I want to store the base64 data of Image URI in a local variable. Can anyone come up with some idea how I can do it??
Hi Chetna,
There's nothing out-of-the-box that supports this. If you google a bit you'll find ways to do that with JavaScript, e.g. here.
I saw many javascript codes and I am new to Javascript, can you tell how to use the javascript code and which code do I need to implement. It should be more helpful for me if you provide any demo for this.
A little clarification, you want to encode image URL as Base64 or image binary data as Base64 String?
I think below assets from Forge can solve your problems: -
Base64 SafeURL encode decode https://www.outsystems.com/forge/component-overview/13869/base64-safeurl-encode-decode
Picture to Base64 https://www.outsystems.com/forge/component-overview/11892/picture-to-base64
It is not URL its URI which I am getting and it look like this data:image/png;base64,iVBORw0KGg... and I want to store iVBORw0KGg... this base64 data in a local variable. I am also using .split function to split the data but it does not work out. Can anyone suggest how I can do without using javascript.
Hi,
Why not do it like this? the Replace() function is available client side as well as server side.
Regards,
Daniel
Your data is already in Base64 format. Simply use replace function to remove "data:image/png;base64," and save in a Text local variable.
as I suggested 30 minutes before already
A URL and a URI are, for all intents and purposes, the same thing. You are talking about a Base64 source for the image, rather than an image URL.
That said, once you have the Base64 extracted the way Daniël proposed, why do you want to store it as Base64 instead of binary? Binary should be less bytes to store, so is more efficient.
Because the Outsystems version which I am using does not support multipart/form-data for binary images so I am sending images in the form of data as Base664.
I think you are confusing a number of things. First, you were talking about the Base64 of an image, but now you're talking about multipart/form-data, which is a way to communicate data via REST. Also you are talking about it being not supported, but for a long time we've had the Multipart/form-data Forge asset that you can use to do the same. Also, if a REST service proscribes the use of Multipart/form-data, you typically need to use that, regardless of whether you send binary data or text.
Also, if you use Binary Data in a REST service, OutSystems will automatically convert the binary data to Base64, so there's no need to do the conversion yourself.
Last, if you actually want to store the images in the database, then you should use binary data, as Base64 is larger. You can always convert it back to Base64. If you only want to use it locally, you could opt for Base64, but like I said, binary data is converted by OutSystems to Base64 when sending it via REST.
I did this but the issue is that it does not work while I run this application on mobile. Can you suggest me any other function which work for both laptop and mobile phones.