336
Views
12
Comments
How to convert image URI to base64.

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??

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

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.

UserImage.jpg
Chetna Upadhyay

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.

2023-03-21 09-05-05
m.irfan.azam

A little clarification, you want to encode image URL as Base64 or image binary data as Base64 String?

2023-03-21 09-05-05
m.irfan.azam
UserImage.jpg
Chetna Upadhyay

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.


2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi,

Why not do it like this?  the Replace() function is available client side as well as server side.

Regards,

Daniel

2023-03-21 09-05-05
m.irfan.azam

Your data is already in Base64 format. Simply use replace function to remove "data:image/png;base64," and save in a Text local variable.

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

as I suggested 30 minutes before already

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

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.

UserImage.jpg
Chetna Upadhyay

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.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Chetna,

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.

UserImage.jpg
Chetna Upadhyay

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.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.