Reputation: 29
I have base64 data and I need to convert to image src I know the format:
document.getElementById('img').setAttribute( 'src', 'data:image/png;base64, stringdatahere' );
But I don't know how to get my data into that string. Thanks
Upvotes: 1
Views: 82
Reputation: 782226
Use string concatenation:
document.getElementById('img').setAttribute( 'src', 'data:image/png;base64,' + dataObject.base64 );
Upvotes: 3
Reputation: 196236
If you have the data in a variable then just
document.getElementById('img').setAttribute( 'src', 'data:image/png;base64,' + dataVariableName );
Upvotes: 2