0

I am receiving the Image as Base64 from the server. I want to decode and display the image. How do I decode base64 to Image ? I dont want to directly paste the base64 string into the image source as its taking alot of time to load the image and also not supported by few browsers.

Below is the code :

// Takes base64 string & returns Image
function decodeBase64Image(base64_string) { };

var Image = decodeBase64Image(base64_string);

<img src={Image} />
4
  • Is your plan to decode the image and store it somewhere on your website, so it can be accessed that way by the page? Commented Dec 22, 2021 at 17:03
  • No,I may plan to download the Image latter. Commented Dec 22, 2021 at 17:19
  • Does this answer your question? convert base64 to image in javascript/jquery Commented Dec 22, 2021 at 17:35
  • No,most of the solutions given follow a similar approach of giving base64 string sirectly to src. What if I want to download the image ? also it is slow. I want to convert base64 to Image object and then do some processing over it Commented Dec 23, 2021 at 5:23

1 Answer 1

3

You might need to make sure the prefix is provided, but decoding shouldn't be necessary.

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4
        //8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
Sign up to request clarification or add additional context in comments.

1 Comment

As stated above,I dont want to paste the base64 string into src directly,for some reason Its very slow to display the image & its not supported by some browsers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.