• Shivaraj_Maacherla
  • NEWBIE
  • 0 Points
  • Member since 2020
  • Senior Software Developer
  • IBM

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hi All
I want to display Images from Apex Object through lightning component,
I'm getting successful responses like " <p><img src="https://shivaraj-dev-ed--c.documentforce.com/servlet/rtaImage?eid=a0A2w00000WG0c3&amp;feoid=00N2w00000K5n42&amp;refid=0EM2w000004C3qa" alt="QRScanner.png"></img></p> " ,
This is what the response I'm getting and when tried to render it on lightning component the same text is printing on UI.I tried using iframes and lightning:formattedRichText but no luck, Please find my code below

Component:- 
<aura:component controller="ECommerce" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="images" type="list"/>
     <aura:iteration items="{!v.images}" var="imgs">
        <div class="slds-box">
            <p>Images are</p>
            {!imgs.Images__c}
            <!--<iframe src="{!imgs.Images__c}" aura:id="frame"/>-->
            <lightning:formattedRichText>{!imgs.Images__c}</lightning:formattedRichText>
         </div>
    </aura:iteration>
</aura:component>

helper :-
({
    getImages : function(component, event, helper) {
        console.log('inside helper');
        var action = component.get("c.getImagess");
        action.setCallback(this,function(res){
            var state = res.getState();
            if(state === 'SUCCESS'){
                var callBackresponse = res.getReturnValue();
                console.log('Res is',callBackresponse[0].Images__c);
                var xyz = callBackresponse[0].Images__c;
                //console.log('after trunctcate',xyz.getAttribute('src'));
                //console.log('Datatype is',typeOf(callBackresponse));
                component.set("v.images",callBackresponse);
              }else if(res === 'ERROR'){
                console.log('Exception is', res.getError());
            }
        });
        $A.enqueueAction(action);
    }
})
--------
Apex:- 
public class ECommerce {
    @AuraEnabled
    public static list<eCommerce__c> getImagess(){
        list<eCommerce__c> eList=[select Images__c from eCommerce__c];
        return eList;
    }
}

Can we write trigger when someone publish content(article page) on salesforce CMS
User-added image