Expand my Community achievements bar.

SOLVED

How to Read & Display Image File in AEM 6.5

Avatar

Level 2

 

Hi All,

In AEM 6.5 I am trying to read the jcr:data (Binary) from jcr:content and convert it to base64 to display the image in frontend page level (HTML).

I can read the jcr:data and converted to base64 but when I am trying to display the same base64 image in HTML it is not properly loaded.

Kindly check below screenshots for your reference.

Does anyone have any ideas or other things I can check for as to why this would not work?

 

I have written the following java code to read the jcr:data from jcr:content and convert it to base64 to display the image in frontend page level (HTML).

 

Ashok884_0-1640844246996.png

 

 

And I got the base64 string as below.

 

"data:image/png;base64,iVBORxoAAABJSERSAAAAKwAAACsIBgAAAOFdccAAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAADP2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4zLWMwMTEgNjYuMTQ1NjYxLCAyMDEyLzAyLzA2LTE0OjU2OjI3ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1wTU06T3JpZ2luYWxEb2N1bWVudElEPSJ4bXAuZGlkOjhlYzY0NzhiLWJkNGUtYzE0Ni1iOTRhLTA3MTUzYjAyMzkwYSIg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Ap7/d2QDtt/vhnC8AP44DMBweh+DXEOzbsQnmlc2C0D9xOOX2wr33Q3pkV4vDYKlRXVBTZQP7hlXQ9zIQHyIUF1sa9aZdJg6D+Uaesz0XeuHDWCT++xVHFFw/26DetjA+bDSGVezZUqNEQ+GxlKgYi61letKWirKjkj+FP4qyI5LLjoiyQcllg6KsX3JZvyhLz/IRSUUj7AcWqnVx+eg+sldC2Qf05EtrEHHV5ZG0Zz2ZlogPkSHJRL+z1zTZCaRTMtlO9sr4WEM1qLeSiAY/q7mewf4gJz/JIotS+8fZJ+ejuA85W2RZav+p0orMGS40FCOo3Q6lFRmKKeQ/eCWaFD+43Uk1ssnZP8o/t0wS7eab0kS2A/KVPP9Cohx/rIC34wjnd6VfUGplk0EV7xrEa7Col/N2KTlYzZ4C7bLs5ipJHz9rLTHFn7dzPsW7N1p2awaY5T8onu2CxNbS3Byf+YmtpcfIHeSLlm+pZx+MGjzP0BlaP6xEFkFi+ynKK/xPyGcdZyIV/wQYAC+hsu7D/JsOAAAAAElFTkSuQmCC"

 

When I am trying to display the same base64 image in HTML it is not properly loaded as showing below.

Ashok884_1-1640844247000.png

 

 

1 Accepted Solution

Avatar

Correct answer by
Employee
4 Replies

Avatar

Level 9

Are you trying it in a form?

like xdp rendered in html5 form?

Avatar

Employee

When I tried to decode this base64 string using online decoder, I am also getting the following only:

Mayank_Tiwari_0-1640845146309.png

It means that the base64 string you are passing is not correct. Can you please try to encode the actual image first using online encoder, to get the expected base64 string, and then compare the expected base64 string with yours? 

Avatar

Level 2

Thank you for your response.

 

Yes i was forgot to mention that point.

I have already observed that like encryption string is not a valid.

But i want to know anything wrong in Base64 encryption logic which i have used or logic for reading the image binary file.

Can you please help me on this?

Avatar

Correct answer by
Employee

Can you please refer to the following links on how to do this:

 

https://stackoverflow.com/questions/17055049/cq5-how-do-i-render-an-image-by-inputstream-from-jcrdat...

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/get-image-files-from-jcr-n...

 

Also, if this doesn't help then please post this on AEM Sites community, as this is not related to AEM Forms.