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>

1 Answer 1

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 Commented Aug 20, 2017 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} />' Commented Aug 20, 2017 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 Commented Aug 20, 2017 at 15:35
  • please sir i need your help Commented Aug 22, 2017 at 8:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .