function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Paridhi Bindal 9Paridhi Bindal 9 

Display Attachment (profile picture) as display picture in LWC img

Hello everyone,

I am trying to display profile picture when a user logs-in in the community. The image file is on Contact object attachment record. How can I add it in img src on LWC?

Thanks.
Best Answer chosen by Paridhi Bindal 9
Paridhi Bindal 9Paridhi Bindal 9
I was able to resolve this by following steps -

1. Encode attachment to BAse64 string by System.EncodingUtil.base64Encode(attachment.body);
2. Add chacheable method that returns the string
3. Using wire get the base64 string and display the image by appending 'data:image/jpeg;base64'.

All the best everyone.


 

All Answers

Paridhi Bindal 9Paridhi Bindal 9
Hello, I am trying to display image from user's contact's attachment file. So I already got the userid, but looking to display the picture from attachment. Thanks.
Paridhi Bindal 9Paridhi Bindal 9
I was able to resolve this by following steps -

1. Encode attachment to BAse64 string by System.EncodingUtil.base64Encode(attachment.body);
2. Add chacheable method that returns the string
3. Using wire get the base64 string and display the image by appending 'data:image/jpeg;base64'.

All the best everyone.


 
This was selected as the best answer