cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Base64 to Image

sagar.d
5-Regular Member

Base64 to Image

Hi,
This the code that I'm using to convert base64 code input into an image output, I have gathered this code from the community itself but it is not working for me... Showing No Image Available error.

var input;
var binaryString = "";
for (var i = 2; i < input.length; i += 2) {
binaryString += String.fromCharCode(
parseInt(
input.substr(i, 2),
16
)
);
}
var result = base64EncodeString(binaryString);

 

@Constantine 

 

t.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
CharlesJi
14-Alexandrite
(To:sagar.d)

Hi @sagar.d, I noticed that your input is already a base64 string and not a binary string.

So you just need to cut the header part (i.e., data&colon;image/png;base64,) and keep the rest:

 

var result = input.split(',')[1];

 

 Hope it helps.

View solution in original post

3 REPLIES 3
CharlesJi
14-Alexandrite
(To:sagar.d)

Hi @sagar.d, I noticed that your input is already a base64 string and not a binary string.

So you just need to cut the header part (i.e., data&colon;image/png;base64,) and keep the rest:

 

var result = input.split(',')[1];

 

 Hope it helps.

sagar.d
5-Regular Member
(To:CharlesJi)

Hi @CharlesJi thanks for the response, really appreciate it.
I have tried removing the header part as you said, and entered the rest in input, still not getting any image.

The input data-type I am using is BLOB, if I use String - the output is a broken image. 

sagar.d
5-Regular Member
(To:CharlesJi)

Thanks a lot!

Top Tags