Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set img src from Byte Array

I need to set the img src property from a byte array that I have in a Object.

<img id="profileImage">
    <spring:bind path="object.profilePicture">
        <input type="file" name="profilePicture" id="profilePicture" path="profilePicture">
    </spring:bind>

I need to display that byte array in the img above the input tag.

like image 914
Rodrigo Juarez Avatar asked May 08 '15 17:05

Rodrigo Juarez


2 Answers

Replace the jpg with the type of image, and [your byte array] with your byte array. You need to convert it to base64 if it isn't already.

<img id="profileImage" src="data:image/jpg;base64, [your byte array]">
like image 149
DonO Avatar answered Oct 15 '22 02:10

DonO


In my case the base64 byte array had to be chunked, in the way:

<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4QCARXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUA
AAABAAAARgEoAAMAAAABAAIAAIdpAAQAAAABAAAATgAAAAAAAABIAAAAAQAAAEgAAAABAAOQAAAH
...

To make this solution works.

like image 33
Francisco M Avatar answered Oct 15 '22 00:10

Francisco M