Click here to Skip to main content
15,997,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am trying to display image from database. I have converted the database image into base 64 format. I am using javascript for the conversion. But its not an image format. My code is as follows:
var che = btoa(data.d.ItemImage1);
$('#imgUpload').attr('src', "data:image/png;base64," + che);
On alerting this, the format will be as follows, but it cannot show an image.
MTAwLDk3LDExNiw5Nyw1OCwxMDUsMTA5LDk3LDEwMywxMDEsNDcsMTA2LDExMiwxMDEsMTAzLDU5LDk4LDk3LDExNSwxMDEsNTQsNTIsNDQsNDcsNTcsMTA2LDQ3LDUyLDY1LDY1LDgxLDgzLDEwNyw5MCw3NCw4MiwxMDMsNjUsNjYsNjUsMTAzLDY5LDY1LDg5LDY1LDY2LDEwMyw2NSw2NSw2OCw0Nyw1NSwxMDMsNjUsNzksODEsODcsODIsMTE4LDg5LDEwOSw4NSw2NSw5MCw2NSw2NSw2NSw2NSw2NSw2NSw2Niw0Nyw0Myw2OSw4Myw2Nyw2OSw4Niw1Miw5Nyw4Nyw4OSw2NSw2NSw2OSw0OSw3OCw2NSw2NywxMTEsNjUsNjUsNjUsNjUsNzMsNjUsNjUsOTksNjYsNzcsMTAzLDY1LDY3LDY1LDY1LDY1LDY1LDcwLDY1LDY1LDY1LDY1LDcxLDczLDY2LDc5LDExOSw2NSw2Nyw2NSw2NSw2NSw2NSw2NiwxMTksNjUsNjUsNjUsNzIsOTAsNzIsODIsMTAzLDY1LDY4LDY1LDY1LDY1LDY1LDY1LDgxLDY1LDY5LDY1LDY1LDY2LDcyLDgzLDgxLDY1LDY4LDY1LDY1LDY1LDY1LDY1LDgxLDY1LDQ3LDY1LDY1LDY3LDk5LDExMCw4MSw2NSw2Niw2NSw2NSw2NSw2NSw2OCwxMDMsNjUsNjUsNjUsNjUsNjgsMTEzLDcyLDY1LDY1LDcyLDY1LDY1LDY1LDcyLDk4LDEwMyw2NSw2NSw2NSw2NSw2Nyw3Miw5Nyw4MSw2NSw2OSw2NSw2NSw2NSw2NSw2NSw4MSw2NSw2NSw2NSw3Miw0OCw2NSw2NSw2NSw2OCwxMTAsNzcsMTA2LDY1LDExOSw3OSw4NCwxMTEsMTE5LDc3LDEyMiwxMTEsMTIwLDc3LDEwNSw2NSwxMjAsNzcsMTIyLDExMSw0OCw3OSw2OCwxMTEsMTIyLDc4LDgxLDY2LDY4LDk4LDUxLDc0LDEwNSw5Nyw4OCw3Nw==
Posted

1 solution

atob and btoa were mozzila specific and IE still doesn't properly support it (as of IE 10, not sure about 11) - but since you get correct (and even padded) string, I don't know what else could be.

Try matching '' and "" you have both in your attr function. Use either double or single quotes, not both.

Check this :
Stackoverflow server solution[^]
 
Share this answer
 
Comments
My Doubt 10-Sep-14 2:35am    
No its just a convertion but I could not get image after the conversion. Image format will be like this:
For Example:
/9j/4AAQSkZJRgABAQAAAQABAAD/4QAqRXhpZgAASUkqAAgAAAABADEBAgAHAAAAGgAAAAAAAABHb29nbGUAAP/bAIQAAwICCgoKCgoKCAoKCggICAoICgoICggICAoICggICAgICAgICAgICAgICAgICggICAgKCgoICA0NCggNCAgKCAEDBAQGBQYKBgYKDA0IDAgNCAwMCAwMDAgMCAwMDAgMCAgICAwMCAgICAgMDAgICAgICAgICAgICAgICAgICAgI/8AAEQgA4QGQAwERAAIRAQMRAf/EAB4AAAEEAwEBAQAAAAAAAAAAAAUDBAYHAQIICQAK/8QAThAAAgECAwQGBwQHBQUHBQEAAQIDABEEEiEFBjFBBxMiUWFxMoGRobHB8AgUI9EzQlJicuHxCRUkgrJDc5Kiwhg0U2N0s9IXVIOToxb/xAAbAQADAQEBAQEAAAAAAAAAAAAAAQIDBAUGB//EACwRAQEBAAICAgEDAwMFAQAAAAABEQIhEjEDQVETYXEEIoEFMsGRodHw8bH/2gAMAwEAAhEDEQA/AOK2xmWcMvZKxLYroQSl2IItzY08QL4fbj/tkaW4kaHl5eHjWkSn+7O/OJjVcmJmA0sBO4AFgAAA1gAANOFqLAsHo83sxLy4pnxEjMMTY3kfW8sx0BawAtw0A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iEQsLW/BOtv3O6o5ccazm5jLa15zqLQmrgH9hC7KO9l+I+VMZ+Fu/ZzY/eFA57QQeBF8QW8ri3Dw86N/8A1nU+3xmIwUUqMQzYnHkWOtoyp0vf9Q28admpkxEujUOJQzvmBBI/O/y/nV8JLS5relmGa4Fhbhx9f5108OumI5gcXwoA8mNFuPq+vlUK3D7Z2OAOrDTkTa/u+NTVam+wsO5sUZGvyEi5hz1UnjSVq3ujXBOpYutuzYXIN7kcLEn2isuV1rwWGKhqxQCbUAhiJaZVFsK15B/GPjWt9MvdTAJWLZsDQCtAamgMigjDHpVlSWGXtDyoogl92paorElSGz0wFvxqkPhpQG1AZU0AoKAf4Opqzq1IM5aMALvCtwPC/wAqrj1SqJYpbVsyoDtLD31tVajEPxuygTpXROSTR9iFddPDz8uNPYVmort3Zf7uhOp+j3d/C1EYcp9B0ezdR2fM9/lz5cP61Ws8O8Vu+pGnEW0+dxoPfUn4sYzd4PGAeBt9d3Ed3zuHist5OjdTex5+Glu7lwuLae69a7qLKrXa25ZUkWv42t7+HAnh8jafGK8jBN0AxsRYW8Lm+lv5mtJL6wvJYvR3u+Fw9x3j52019uvxqOftW/aO9I8N727rce6/P9b6111UtLexbaG7wMJuL3jAsbcLWub8+fH51FnS+PHHC68fbXkvQKxVcMe2Cx6yO3KRNO+xGlEqMW39mDaCieBWNmfEO1m09BHvYmwuGcDU86P/ACmrFxhDbPwQtqTtNz/xRDXzGmumtqvSQzo52sCVA7r+o2sfz48+dqrgXKdLWWXh5fXyrpjA+gxvxoAw20RpfTTX68KQaffBfQ++lZAKYDaPianxxUuJxsHbjLazt/xG4+vA+qpsVKmWzt+Zl0Ez+tifZxt9aUsi/Kp1ux0lt6MvbHIj0x58Aw87HxOtZ3ji5ys9p/gttI4urg+4jzB1FLGuguL2qCTrTkRboTu9NeRfO/zq76TPaeqaxbNmoDcPQH16A3oAfjuNVCpLC+
Sinisa Hajnal 10-Sep-14 2:56am    
Did you try it on firefox, chrome and IE? I don't see anything wrong with your code per se. In the solution I mentioned things I would check.

Also, create an empty page with src element with your base64 string and see that it shows if no javascript is involved.
My Doubt 10-Sep-14 3:17am    
I have tested with google chrome and firefox but the problem still there..
My Doubt 10-Sep-14 3:24am    
there will be having / and + in the image format but in my conversion I could not get any symbols like that..
Sinisa Hajnal 10-Sep-14 3:47am    
Use some online converter and see if it matches your conversion...Did you try empty page with static string?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900