2

I need some help on lightning components. I'm trying to show attachment image using lightning components but the image is not shown.

<aura:component controller="AttachmentClass">
<aura:attribute name="myObjects" type="Attachment[]"/>
    <aura:attribute name="attchid" type="String" default="00P900000115nZx"/>
    <aura:handler name="init" value="{!this}" action="{!c.getOpps}"/>
      <aura:attribute name="prefixURL" type="String" default="/sfc/servlet.shepherd/version/download/"/>

   <h2>All Record</h2>
       <table border="2px" ><tbody>
        <aura:iteration items="{!v.myObjects}" var="SelectOperation">
          <tr>
            <th>ParentId</th>
              <th>BodyLength</th>
                 <th>Image</th>
            </tr>
    .   <tr>   
            <td><option text="{!SelectOperation.ParentId}"/></td>
       <td><option text="{!SelectOperation.BodyLength}"/></td>

       <td><img class="mythumbnail" src="{!'/servlet/servlet.FileDownload?file='+SelectOperation.attchid}" width="100" height="100"/></td>
             <td><img src="{!'/servlet/servlet.FileDownload?file=' + v.attchid}" alt=""/></td>
       </tr>
       </aura:iteration>
       </tbody></table>

</aura:component>
3

Your aura:iteration loop through your myObjects variable which is an array of Attachment objects.

Then, each SelectOperation variable is an Attachment object. So the attchid property doesn't exist. If you want to display the attachment you have to use the Id property like this:

<img class="mythumbnail" src="{!'/servlet/servlet.FileDownload?file='+SelectOperation.Id}" width="100" height="100"/>
4
  • Thankyou sir for your ans. but in this cod i can only see image i can not see the pdf file – Lokesh Malviya Aug 20 '17 at 4:37
  • @LokeshMalviya You cannot show a pdf deom an HTML IMG tag. Instead you should use a either a javascript pdf viewer like the PDF.JS, or maybe you can render the pdf as it own page inside an iframe: <iframe src={!'/servlet/servlet.FileDownload?file='+SelectOperation.Id} />' – Itai Shmida Aug 20 '17 at 5:07
  • tq for your again ans. sir but i have allready used it and using this cod we can not see image in responsive way – Lokesh Malviya Aug 20 '17 at 15:35
  • please sir i need your help – Lokesh Malviya Aug 22 '17 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.